Exemple #1
0
 /**
  * Deletes assoc with pub version
  *
  * @param   integer  $vid
  * @param   integer  $pid
  * @return  void
  */
 public function deleteVersionExistence($vid, $pid)
 {
     // Delete authors
     $pa = new Tables\Author($this->database);
     $authors = $pa->deleteAssociations($vid);
     // Delete attachments
     $pContent = new Tables\Attachment($this->database);
     $pContent->deleteAttachments($vid);
     // Delete screenshots
     $pScreenshot = new Tables\Screenshot($this->database);
     $pScreenshot->deleteScreenshots($vid);
     // Delete access accosiations
     $pAccess = new Tables\Access($this->database);
     $pAccess->deleteGroups($vid);
     // Delete audience
     $pAudience = new Tables\Audience($this->database);
     $pAudience->deleteAudience($vid);
     // Build publication path
     $path = Helpers\Html::buildPubPath($pid, $vid, $this->config->get('webpath'), '', 1);
     // Delete all files
     if (is_dir($path)) {
         Filesystem::deleteDirectory($path);
     }
     return true;
 }
 /**
  * Conversion for publications created in a non-curated flow
  *
  * @param   object $pub
  * @return  boolean
  */
 public function convertToCuration($pub = NULL)
 {
     $pub = $pub ? $pub : $this->_pub;
     $oldFlow = false;
     // Load attachments
     $pub->attachments();
     if (!isset($pub->_attachments) || empty($pub->_attachments['elements'])) {
         // Nothing to convert
         return false;
     }
     // Get supporting docs element manifest
     $sElements = self::getElements(2);
     $sElement = $sElements ? $sElements[0] : NULL;
     // Loop through attachments
     foreach ($pub->_attachments['elements'] as $elementId => $elementAttachments) {
         if (empty($elementAttachments)) {
             continue;
         }
         // Check if any attachments are missing element id
         foreach ($elementAttachments as $elAttach) {
             if ($elAttach->element_id == 0) {
                 // Save elementid
                 $row = new Tables\Attachment($this->_db);
                 if ($row->load($elAttach->id)) {
                     $markId = $elAttach->role != 1 && $sElement ? $sElement->id : $elementId;
                     $row->element_id = $markId;
                     $row->store();
                 }
                 $oldFlow = true;
                 // will need to make further checks
             }
         }
     }
     if (!$oldFlow) {
         return false;
     }
     // Get gallery element manifest
     $elements = self::getElements(3);
     $element = $elements ? $elements[0] : NULL;
     // Retrieve screenshots
     $pScreenshot = new Tables\Screenshot($this->_db);
     $shots = $pScreenshot->getScreenshots($pub->version_id);
     // Transfer gallery files to the right location
     if ($element && $shots) {
         // Get attachment type model
         $attModel = new Attachments($this->_db);
         $fileAttach = $attModel->loadAttach('file');
         // Set configs
         $configs = $fileAttach->getConfigs($element->manifest->params, $element->id, $pub, $element->block);
         // Get gallery path
         $galleryPath = Helpers\Html::buildPubPath($pub->id, $pub->version_id, '', 'gallery', 1);
         if (is_dir($galleryPath)) {
             foreach ($shots as $shot) {
                 $objPA = new Tables\Attachment($this->_db);
                 if (is_file($galleryPath . DS . $shot->srcfile) && !$objPA->loadElementAttachment($pub->version_id, array('path' => $shot->filename), $element->id, 'file', $element->manifest->params->role)) {
                     $objPA = new Tables\Attachment($this->_db);
                     $objPA->publication_id = $pub->id;
                     $objPA->publication_version_id = $pub->version_id;
                     $objPA->path = $shot->filename;
                     $objPA->type = 'file';
                     $objPA->created_by = User::get('id');
                     $objPA->created = Date::toSql();
                     $objPA->role = $element->manifest->params->role;
                     $objPA->element_id = $element->id;
                     $objPA->ordering = $shot->ordering;
                     if (!$objPA->store()) {
                         continue;
                     }
                     // Check if names is already used
                     $suffix = $fileAttach->checkForDuplicate($configs->path . DS . $objPA->path, $objPA, $configs);
                     // Save params if applicable
                     if ($suffix) {
                         $objPA->params = 'suffix=' . $suffix . "\n";
                     }
                     // Copy file into the right spot
                     $configs->copyFrom = $galleryPath . DS . $shot->srcfile;
                     if (!$fileAttach->publishAttachment($objPA, $pub, $configs)) {
                         $objPA->delete();
                     }
                 }
             }
         }
     }
     // Check if published version has curation manifest saved
     $row = new Tables\Version($this->_db);
     if ($pub->state == 1 && !$pub->curation) {
         if ($row->load($pub->version_id)) {
             $row->curation = json_encode($this->_manifest);
             $row->store();
         }
     }
     // Mark as curated
     $row->saveParam($row->id, 'curated', 1);
     return true;
 }