Introduction

Starting with Version 4.1.5 Build #1910, the CometPublication plugin delivered with the PublishingServer provides a couple of methods, which allow better integration of the Publication Management Planner with priint:comet InDesign Desktop and Server Plugins.
The standard set of scripts and configurations created with new Comet projects has also been updated to support these new features.

This documentation shows, how to optimize existing Comet projects or implementing new functionality based on the CometPublicationCScriptAddOns plugin.

At least, the two script optimizations described in Optimize Document Open Events On Server and Optimize Document Save Events On Server should be taken into account. It's highly recommended updating the configuration of existing Comet projects like shown in these examples.

Requirements

Implementing publication scripts as described in this documentation requires

Integrating CometPublicationCScriptAddOns

To integrate the cscript add-ons, you simply have to include the generated cscript stub into your script:

#include 
    "[pubserver]/plugin/com.priint.pubserver.comet.bridge.publication.CometPublicationCScriptAddOns.c"      
      
The functions available with this include are listed below.

Method Overview

The CometPublicationCScriptAddOns plugin (contained in the CometPublication plugin library) defines the following methods including cscript integration:

Usage Examples

Create a new Master Document

Description

This script asks for a master document name, creates a new master document record and uploads the current front document to the Publication Planner.
If the server is configured for priint:pdf renderer, the document will first be exported as a w2ml file and then uploaded to the server.

This script is included in the standard set of panel scripts created with a new Comet project starting with version 4.1.5, Build #1910.
This means: if your project was created with this or a later version, there is no need to add this script manually to your project.
If not, you can copy, adapt & paste the following code to a new panel script (we recommend creating a "Publication" panel script in the "InDesign Desktop Panels" node in ISON).

Functional Description

Pre Conditions

Variability in Process Flow Post Conditions

#include "internal/panels.h"
#include 
   "[pubserver]/plugin/com.priint.pubserver.comet.bridge.publication.CometPublicationCScriptAddOns.c"

int main() {
  char * documentPath = alloc(4096);
  char * documentId   = 0;
  int    result   = -1;
  int    test     = 0;
  char * pathTmp  = alloc(4096);
  char * nameTmp  = alloc(4096);
  char * extender = alloc(4096);
  char * buffer   = alloc(4096);
  char * s1       = alloc(4096);
  char * s2       = alloc(4096);
  int    dialogResult = 0;
  XMLTree tree;
  
  for (;;) {
    if (document::get_modified(gDocument) != 0) {
      showmessage("DOCUMENT_IS_MODIFIED");
      break;
    }
    test = document::path(documentPath, gDocument);
    if (test == 0) {
      showmessage("DOCUMENT_HAS_NO_PATH");
      break;
    }
    
    document::name(buffer, gDocument);
    strcpy(s1, translate("INPUT_MASTERDOCUMENT_NAME"));
    strcpy(s2, translate("TITLE_MASTERDOCUMENT_NAME"));
    dialogResult = askstring(buffer, 
              s1, 
              s2, 0, 0, 0);
    if (dialogResult == 0) {
      break;
    }
    
    progress::start(translate("UPLOADING_MASTER_DOCUMENT"), 4);
    if (strlen(buffer) == 0) {
      document::name(buffer, gDocument);
    }
    documentId = createMasterDocument(buffer);
    
    if (!documentId || strlen(documentId) == 0) {
      showerror("NEW_DOCUMENT_ID_EMPTY");
      break;
    }
    
    // the document - no matter if w2ml or indd format - must be saved in the
    // XCache folder, so it is assumed to be a publication document:
    progress::step(translate("PREPARING"), 1);
    strcat(pathTmp, "$CACHE/publication/");
    strcat(pathTmp, soap::client(soap::connection(), buffer));
    extender  = getRendererFileType();
    sprintf(nameTmp, "%s%s", documentId, extender);

    // W2ML export mode
    if (strstr(extender, ".w2ml") == extender) {
      strcat(pathTmp, "/");
      strcat(pathTmp, nameTmp); 
      // export to XCache ...
      tree = server::get_elements(gDocument, kScopeDocument, 0, 
                           "xmlversion:3.1;content:tagged,properties;");
      document::set_modified(gDocument, 0);
      xmlquery::write(tree, pathTmp);
      xmlquery::close(tree, 1);
    }
    // InDesign upload mode
    else {
      // copy to XCache ...
      file::duplicate(documentPath, pathTmp, nameTmp); 
      strcat(pathTmp, "/");
      strcat(pathTmp, nameTmp);
    } 
    // since there is no document data yet uploaded to the server, we cannot
    // regularly checkout the document. However, the server status must be
    // checked out, otherwise subsequent checkin calls will fail:
    markDocumentCheckedOut(documentId);

    progress::step(translate("UPLOADING"), 1);
    priint::checkin(documentId, pathTmp);
    document::close(gDocument, 0);
    progress::step(translate("CLEANING_UP"), 1);
    file::remove(pathTmp);
    result = 0;
    break;  
  }
  progress::step(translate("REFRESHING"), 1);
  if (result == 0) {
    // server side processing takes some time. We want to make sure,
    // that the updated list is shown after refresh:
    system::sleep(1000);
    placeholder::reload_panel(kPanelPublications, 1);
  }
  progress::stop();
  if (documentId)   release(documentId);
  if (documentPath) release(documentPath);
  if (pathTmp)      release(pathTmp);
  if (nameTmp)      release(nameTmp);
  if (extender)     release(extender);
  if (buffer)       release(buffer);
  if (s1)           release(s1);
  if (s2)           release(s2);
  return result;
}

Optimize Document Open Events on Server 

Description

This script is executed, after a document has been opened. If run with InDesignServer, it checks, whether the document being opened is a publication document. If yes, the scripts configured for publication documents are executed (as configured in event script publication::after checkout).

This is the standard version of the document::after open event script created with a new Comet project starting with version 4.1.5, Build #1910.
In earlier versions, the publication::after checkout routines were executed for all documents, which could cause errors on server and client side. We therefore recommend updating the document::after open scripts in older projects as shown below.

Functional Description

Pre Conditions

Post Conditions

#include 
    "[pubserver]/plugin/com.priint.pubserver.comet.bridge.publication.CometPublicationCScriptAddOns.c"
int main() {
  if (system::is_server()) {
    if (isPublicationDocument(gDocumentID)) {
      publication::aftercheckout(gDocumentID, gDocumentPath);
    }
  }
  return 0;
}

New Version of document::open / publication::after checkout scripts

With PublishingServer 4.1.5.1 Build #2327, new versions of the document:open and publication::after checkout scripts have been established: these scripts handle the situation, when a document has just been checked out and closed without saving and then is reopened locally.

The former behaviour was:

(the latter also applies for documents, which have been saved).

Unfortunately, parts pf the functionality have to bee implemented twice, because depending on the situation, certain environment variables are or are not defined in the script context. For new Comet projects, the improved versions of the scripts is generated automatically, for old projects it's highly recommended updating the scripts as follows:

publication::after checkout

int main () {
  int result = 0;
  wtlog ("", "\n***************************************\n* Publication: store publication / documentId '%s' in document xml structure, local path: '%s'\n", gDocumentID, gDocumentPath);
  result = xml::set_document_attribute(gDocument, "documentId", gDocumentID);
  if (document::get_modified()) {
    // document has to be saved in this stage, otherwise the documentId
    // documentId and thus linkage to the publication record might get lost
    // if the document is closed. 
    document::save();
  }
  result = xml::set_document_attribute(gDocument, 
            "publication", publication::get_rootpublication_id (gDocumentID));
  result = publication::apply_parameters (gDocument, gDocumentID);
  result = document::set_display_name (gDocument, publication::get_label (gDocumentID));
  return result;
}

document::after open

#include "[pubserver]/plugin/com.priint.pubserver.comet.bridge.publication.CometPublicationCScriptAddOns.c"
int main() {
  int   result = 0;
  char *   documentId = alloc(4096);
  if (system::is_server()) {
    strcpy(documentId, gDocumentID);
  }
  else {
      xml::get_document_attribute(gDocument, "documentId", documentId);
  }

  if (strlen(documentId) && isPublicationDocument(documentId)) {
    result = xml::set_document_attribute(gDocument,
                  "publication", publication::get_rootpublication_id (documentId));
      result = publication::apply_parameters (gDocument, documentId);
      result = document::set_display_name (gDocument, publication::get_label (documentId));
  }

  release(documentId);
  return result;
}

Optimize Document Save Events on Server 

Description

This script is executed, after a document has been saved. If run with InDesignServer, it checks, whether the document being saved is a publication document. If yes, the scripts configured for publication documents are executed (as configured in event script publication::after save and publication::checkin).

This is the standard version of the document::after save event script created with a new Comet project starting with version 4.1.5, Build #1910.
In earlier versions, the publication::after save routines were executed for all documents, which could cause errors on server and client side and also caused unnecessary processing on client and server side (generating and uploading meta data etc.) . We therefore recommend updating the document::after save scripts in older projects as shown below.

Functional Description

Pre Conditions

Post Conditions

#include 
    "[pubserver]/plugin/com.priint.pubserver.comet.bridge.publication.CometPublicationCScriptAddOns.c"

int main() {
  if (system::is_server()) {
    if (isPublicationDocument(gDocumentID)) {
      publication::aftersave(gDocumentID, gDocumentPath);
      publication::checkin(gDocumentID, gDocumentPath);
    }
  }
  return 0;
}

Create Metadata for a Document

Description

This script creates the meta data package as it's being generated upon checkin of a publication document and saves the files in a folder next to the current document.

The first version is quite complex, because in priint:comet Plug-In <= R23333, some functionality essential for meta data generation (namely ceating the items.xml) were not available as cscript functions.
Two shorter versions of this script for newer priint:comet Plug-Ins (4.1 resp. 4.1.5 > R23353) are listed below.

You can copy, adapt & paste this script to a panel script (we recommend creating a "Publication" panel script in the "InDesign Desktop Panels" node in ISON)

Functional Description

Pre Conditions

Post Conditions

#include
    "[pubserver]/plugin/com.priint.pubserver.comet.bridge.publication.CometPublicationCScriptAddOns.c"
#include "internal/products.h"

char * targetFilePath(char * result, char * parentFolder, char * fileName) {
  strcpy(result, parentFolder);
  strcat(result, "/");
  strcat(result, fileName);
  return result;
}

char * product2itemXML(Product product, char * destination, int * size) {
  char * buffer = alloc(4096);
  char * stmp   = alloc(4096);
  int    itmp   = 0;
  
  destination = str_append(destination, "  <item>\n", size);
  
  itmp = product::get(product, kID);
  sprintf(buffer, "    <ID>%d</ID>\n", itmp);
  destination = str_append(destination, buffer, size);
  
  itmp = product::get(product, kID2);
  sprintf(buffer, "    <ID2>%d</ID2>\n", itmp);
  destination = str_append(destination, buffer, size);
  
  itmp = product::get(product, kID3);
  sprintf(buffer, "    <ID3>%d</ID3>\n", itmp);
  destination = str_append(destination, buffer, size);
  
  strcpy(stmp, product::gets(product, kStringID));
  sprintf(buffer, "    <stringID>%s</stringID>\n", stmp);
  destination = str_append(destination, buffer, size);
  
  itmp = product::get(product, kPageitemid);
  sprintf(buffer, "    <pageitemID>%d</pageitemID>\n", itmp);
  destination = str_append(destination, buffer, size);
  
  itmp = product::get(product, kProductDocPosition);
  sprintf(buffer, "    <document-position>%d</document-position>\n", itmp);
  destination = str_append(destination, buffer, size);
  
  itmp = product::get(product, kClassid);
  sprintf(buffer, "    <classID>%d</classID>\n", itmp);
  destination = str_append(destination, buffer, size);
  
  itmp = product::get(product, kElementid);
  sprintf(buffer, "    <elementID>%d</elementID>\n", itmp);
  destination = str_append(destination, buffer, size);
  
  itmp = product::get(product, kPreRuleid);
  sprintf(buffer, "    <preruleID>%d</preruleID>\n", itmp);
  destination = str_append(destination, buffer, size);
  
  strcpy(stmp, product::get(product, kPreRuleparams));
  sprintf(buffer, "    <preruleParams>%s</preruleParams>\n", stmp);
  destination = str_append(destination, buffer, size);
  
  itmp = product::get(product, kPostRuleid);
  sprintf(buffer, "    <postruleID>%d</postruleID>\n", itmp);
  destination = str_append(destination, buffer, size);
  
  strcpy(stmp, product::get(product, kPostRuleparams));
  sprintf(buffer, "    <postruleParams>%s</postruleParams>\n", stmp);
  destination = str_append(destination, buffer, size);
  
  itmp = product::get(product, kProductType);
  if (itmp == 4) {
    sprintf(buffer, "    <type>pagetemplate</type>\n");
  }
  else {
    sprintf(buffer, "    <type>product</type>\n");
  }
  destination = str_append(destination, buffer, size);

  if (itmp == 1) {
    sprintf(buffer, "    <status>inserted</status>\n");
  }
  else if (itmp == 2) {
    sprintf(buffer, "    <status>moved</status>\n");
  }
  else if (itmp == 3) {
    sprintf(buffer, "    <status>removed</status>\n");
  }
  else {
    sprintf(buffer, "    <status>normal</status>\n");
  }    
  destination = str_append(destination, buffer, size);
  
  itmp = product::get(product, kProductPageType);
  sprintf(buffer, "    <pageType>%d</pageType>\n", itmp);
  destination = str_append(destination, buffer, size);
  
  destination = str_append(destination, "  </item>\n", size);  
  
  release(buffer);
  release(stmp);
  
  return destination;
}

int main() {
  char * documentPath = alloc(4096);
  int    result   = -1;
  int    test     = 0;
  char * targetFolder    = alloc(4096);
  char * targetFile      = alloc(4096);
  char * metadataOptions = alloc(4096);
  char * buffer    = 0;
  char * s1        = alloc(4096);
  char * s2        = alloc(4096);
  int dialogResult = 0;
  
  ProductList products = 0;
  Product   product    = 0;
  
  int     productCount = 0;
  int     i            = 0;
  int     bufferSize   = 4096;
  
  int     itemsFile;
  
  XMLTree tree = 0;
  
  for (;;) {
    if (document::get_modified(gDocument) != 0) {
      showmessage("DOCUMENT_IS_MODIFIED");
      break;
    }
    test = document::path(documentPath, gDocument);
    if (test == 0) {
      showmessage("DOCUMENT_HAS_NO_PATH");
      break;
    }
    progress::start(translate("GENERATING_METADATA"), 7);
  
    buffer = getMetadataOptions();  
    strcpy(metadataOptions, buffer);
    
    strcpy(s1, translate("INPUT_METADATA_OPTIONS"));
    strcpy(s2, translate("TITLE_METADATA_OPTIONS"));
    
    dialogResult = askstring(metadataOptions, 
              s1, 
              s2, 0, 0, 0);
    
    if (dialogResult == 0) {
      break;
    }
    
    strcpy(targetFolder, documentPath);
    strcat(targetFolder, ".meta/");
  
    targetFile = targetFilePath(targetFile, targetFolder, "spreads.xml");
    progress::step(translate("GENERATING", targetFile), 1);
    tree = server::get_spreads(gDocument, kScopeDocument, 0, metadataOptions);
    xmlquery::write(tree, targetFile);
    xmlquery::close(tree);  
    
    targetFile = targetFilePath(targetFile, targetFolder, "elements.xml");
    progress::step(translate("GENERATING", targetFile), 1);
    tree = server::get_elements(gDocument, kScopeDocument, 0, metadataOptions);
    xmlquery::write(tree, targetFile);
    xmlquery::close(tree);
    
    targetFile = targetFilePath(targetFile, targetFolder, "groups.xml");
    progress::step(translate("GENERATING", targetFile), 1);
    tree = server::get_cometgroups(gDocument, kScopeDocument, 0, metadataOptions);
    xmlquery::write(tree, targetFile);
    xmlquery::close(tree);
    
    targetFile = targetFilePath(targetFile, targetFolder, "placeholders.xml");
    progress::step(translate("GENERATING", targetFile), 1);
    tree = server::get_placeholders(gDocument, kScopeDocument, 0, metadataOptions);
    xmlquery::write(tree, targetFile);
    xmlquery::close(tree);
    
    targetFile = targetFilePath(targetFile, targetFolder, "notes.xml");
    progress::step(translate("GENERATING", targetFile), 1);
    tree = server::get_notes(gDocument, kScopeDocument, 0, metadataOptions);
    xmlquery::write(tree, targetFile);
    xmlquery::close(tree);
    
    // finally the w2ml file
    strcat(metadataOptions, ";xmlversion:3.1;content:tagged,properties;");
    targetFile = targetFilePath(targetFile, targetFolder, "document.w2ml");
    progress::step(translate("GENERATING", targetFile), 1);
    tree = server::get_elements(gDocument, kScopeDocument, 0, metadataOptions);
    xmlquery::write(tree, targetFile);
    xmlquery::close(tree);
    
    // unfortunately, there is no cscript function to directly export 
    // the "items.xml" from document:
    targetFile = targetFilePath(targetFile, targetFolder, "items.xml");
    progress::step(translate("GENERATING", targetFile), 1);
    products = productlist::get_established(gDocument);
    productCount = productlist::length(products);
    strcpy(s1, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
    strcat(s1, "<psc:items ");
    strcat(s1, "xmlns:psc=\"http://comet.werk-ii.com/psc_items\" ");
    strcat(s1, "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ");
    strcat(s1, "xsi:schemaLocation=\"http://comet.werk-ii.com/psc_items psc_items.xsd\">\n");
    strcat(s1, "<!-- CAUTION! This item XML was generated by a cscript.     -->\n");
    strcat(s1, "<!-- The following elements therefore are missing:          -->\n");
    strcat(s1, "<!-- * groupID (ID of the CometGroup created for this item) -->\n");
    strcat(s1, "<!-- * layout_layers (layout layers used while building)    -->\n");

    for (i = 0; i < productCount; ++i) {
      product = productlist::get(products, i);
      s1 = product2itemXML(product, s1, &bufferSize);  
    }
    s1 = str_append(s1, "</items>", &bufferSize);
    
    itemsFile = file::open(targetFile, "w");
    file::write(itemsFile, s1, 0);
    file::close(itemsFile);
    
    document::set_modified(gDocument, 0);
        
    result = 0;
    break;  
  }
  progress::stop();
  if (documentPath)   release(documentPath);
  if (targetFolder)   release(targetFolder);
  if (targetFile)     release(targetFile);
  if (buffer)         release(buffer);
  if (s1)             release(s1);
  if (s2)             release(s2);
  return result;
}

With priint:comet Plug-Ins >= 4.1 R23353

#include 
    "[pubserver]/plugin/com.priint.pubserver.comet.bridge.publication.CometPublicationCScriptAddOns.c"
#include "internal/products.h"

char * targetFilePath (char * result, char * parentFolder, char * fileName) {
  strcpy(result, parentFolder);
  strcat(result, "/");
  strcat(result, fileName);
  return result;
}

int main() {
  char * documentPath = alloc(4096);
  int    result = -1;
  int    test = 0;
  char * targetFolder = alloc(4096);
  char * targetFile   = alloc(4096);
  char * metadataOptions = alloc(4096);
  char * buffer   = 0;
  char * s1 = alloc(4096);
  char * s2 = alloc(4096);
  int dialogResult = 0;
  
  XMLTree tree = 0;
  
  for (;;) {
    if (document::get_modified(gDocument) != 0) {
      showmessage ("DOCUMENT_IS_MODIFIED");
      break;
    }
    test = document::path (documentPath, gDocument);
    if (test == 0) {
      showmessage ("DOCUMENT_HAS_NO_PATH");
      break;
    }
    progress::start(translate ("GENERATING_METADATA"), 6);
  
    buffer = getMetadataOptions();  
    strcpy(metadataOptions, buffer);
    
    strcpy (s1, translate("INPUT_METADATA_OPTIONS"));
    strcpy (s2, translate("TITLE_METADATA_OPTIONS"));
    
    dialogResult = askstring (metadataOptions, 
              s1, 
              s2, 0, 0, 0);
    
    if (dialogResult == 0) {
      break;
    }
    
    strcpy(targetFolder, documentPath);
    strcat(targetFolder, ".meta/");
  
      
    targetFile = targetFilePath(targetFile, targetFolder, "spreads.xml");
    progress::step(translate("GENERATING", targetFile), 1);
    tree = server::get_spreads(gDocument, kScopeDocument, 0, metadataOptions);
    xmlquery::write (tree, targetFile);
    xmlquery::close (tree);
    
    
    targetFile = targetFilePath(targetFile, targetFolder, "elements.xml");
    progress::step(translate("GENERATING", targetFile), 1);
    tree = server::get_elements(gDocument, kScopeDocument, 0, metadataOptions);
    xmlquery::write (tree, targetFile);
    xmlquery::close (tree);
    
    targetFile = targetFilePath(targetFile, targetFolder, "groups.xml");
    progress::step(translate("GENERATING", targetFile), 1);
    tree = server::get_cometgroups(gDocument, kScopeDocument, 0, metadataOptions);
    xmlquery::write (tree, targetFile);
    xmlquery::close (tree);
    
    targetFile = targetFilePath(targetFile, targetFolder, "placeholders.xml");
    progress::step(translate("GENERATING", targetFile), 1);
    tree = server::get_placeholders(gDocument, kScopeDocument, 0, metadataOptions);
    xmlquery::write (tree, targetFile);
    xmlquery::close (tree);
    
    targetFile = targetFilePath(targetFile, targetFolder, "notes.xml");
    progress::step(translate("GENERATING", targetFile), 1);
    tree = server::get_notes (gDocument, kScopeDocument, 0, metadataOptions);
    xmlquery::write (tree, targetFile);
    xmlquery::close (tree);
    
    targetFile = targetFilePath(targetFile, targetFolder, "items.xml");
    progress::step(translate("GENERATING", targetFile), 1);
    tree = server::get_items (gDocument, kScopeDocument, 0, metadataOptions);
    xmlquery::write (tree, targetFile);
    xmlquery::close (tree);
    
    // finally the w2ml file
    strcat(metadataOptions, ";xmlversion:3.1;content:tagged,properties;");
    targetFile = targetFilePath(targetFile, targetFolder, "document.w2ml");
    progress::step(translate("GENERATING", targetFile), 1);
    tree = server::get_elements (gDocument, kScopeDocument, 0, metadataOptions);
    xmlquery::write (tree, targetFile);
    xmlquery::close (tree);
    
    document::set_modified(gDocument, 0);
        
    result = 0;
    break;  
  }
  progress::stop();
  if (documentPath)   release(documentPath);
  if (targetFolder)  release(targetFolder);
  if (targetFile)    release(targetFile);
  if (buffer)      release(buffer);
  if (s1)        release(s1);
  if (s2)        release(s2);
  return result;
}

Using the all-in-one priint:create_metadata function

This script creates a zipped meta data folder, as it's being uploaded with the document upon checkin, intermediate files are deleted.
The script allows to override certain options for meta data generation with user settings.

#include 
    "[pubserver]/plugin/com.priint.pubserver.comet.bridge.publication.CometPublicationCScriptAddOns.c"

int main() {
  char *   documentPath = alloc(4096);
  int      result = -1;
  char *   metadataOptions = alloc(4096);
  char *   s1 = alloc(4096);
  char *   s2 = alloc(4096);
  int   dialogResult = 0;
  int   test = 0;
    
  for (;;) {
    if (document::get_modified(gDocument) != 0) {
      showmessage ("DOCUMENT_IS_MODIFIED");
      break;
    }
    test = document::path (documentPath, gDocument);
    if (test == 0) {
      showmessage ("DOCUMENT_HAS_NO_PATH");
      break;
    }
    progress::start(translate ("GENERATING_METADATA"), 2);
  
    strcpy(metadataOptions, getMetadataOptions());
    
    strcpy (s1, translate("INPUT_METADATA_OPTIONS"));
    strcpy (s2, translate("TITLE_METADATA_OPTIONS"));
    
    dialogResult = askstring (metadataOptions, 
              s1, 
              s2, 0, 0, 0);
    if (dialogResult == 0) {
      break;
    }
    progress::step(translate ("GENERATING_METADATA"));
      
    result = priint::create_metadata(gDocument, 0, metadataOptions);
    break;
  }
  progress::step(translate ("GENERATING_METADATA"));
  if (s1)              release(s1);
  if (s2)              release(s2);
  if (documentPath)    release(documentPath);
  if (metadataOptions) release(metadataOptions);
  progress::stop();
  return result;
}

Delete a Document / Master Document from Publication Panel

Description

This script deletes a document or master document (i.e.: set the "deleted" flag to 1). Of course, you should consider carefully, if you want to expose this functionality via a panel script to all users.

Functional Description

Pre Conditions

Post Condition

#include "internal/panels.h"
#include 
    "[pubserver]/plugin/com.priint.pubserver.comet.bridge.publication.CometPublicationCScriptAddOns.c"

int main() {
  IDTypeList selectedEntries = idtypelist::alloc(kPanelPublications, kSelected);
  int index;
  int size = idtypelist::length(selectedEntries);
  
  if (size == 0) {
    alert("OK", 0, 0, 1, 3, translate("PLEASE_SELECT_DOCUMENTS"));
  }
  progress::start(translate("PROCESSING"), size);
  
  for (index = 0; index < size; ++index) {
    IDType entry = idtypelist::get(selectedEntries, index);
    if (idtype::id(entry) != 2) {
      alert("OK", 0, 0, 2, 4, translate("CAN_ONLY_DELETE_DOCUMENTS", idtype::stringid(entry)));
    }
    else {
      int doit = alert("OK", "Cancel", 0, 2, 4, 
                       translate("DOCUMENT_REALLY_DELETE", idtype::stringid(entry)));
      progress::step(translate("DELETING"), 1);
      if (doit == 1) { 
        deleteDocument(idtype::stringid(entry));
      }
    }
  }
  progress::step(translate("REFRESHING"), 1);
  placeholder::reload_panel(kPanelPublications, 1);
  progress::stop();
  idtypelist::release(selectedEntries);
  return 0;
}

Close a Document / Master Document from Publication Panel

Description

This script marks a document as closed. This is the same functionality like unlocking a document from the "Checked out documents" panel in the Publication Planner. Of course, you should consider carefully, if you want to expose this functionality via a panel script to all users.

Functional Description

Pre Conditions

Post Condition

#include "internal/panels.h"
#include "[pubserver]/plugin/com.priint.pubserver.comet.bridge.publication.CometPublicationCScriptAddOns.c"

int main() {
  IDTypeList selectedEntries = idtypelist::alloc(kPanelPublications, kSelected);
  int index;
  int size = idtypelist::length(selectedEntries);
  
  if (size == 0) {
    alert("OK", 0, 0, 1, 3, translate("PLEASE_SELECT_DOCUMENTS"));
  }
  progress::start(translate("PROCESSING"), size);
  
  for (index = 0; index < size; ++index) {
    IDType entry = idtypelist::get(selectedEntries, index);
    if (idtype::id(entry) != 2) {
      alert("OK", 0, 0, 2, 4, translate("CAN_ONLY_CLOSE_DOCUMENTS", idtype::stringid(entry)));
    }
    else {
      int doit = alert("OK", "Cancel", 0, 2, 4,
                       translate("DOCUMENT_REALLY_CLOSE", idtype::stringid(entry)));
      progress::step(translate("CLOSING"), 1);
      if (doit == 1) { 
        markDocumentClosed(idtype::stringid(entry));
      }
    }
  }
  progress::step(translate("REFRESHING"), 1);
  placeholder::reload_panel(kPanelPublications, 1);
  progress::stop();
  idtypelist::release(selectedEntries);
  return 0;
}