Beispiel #1
0
 /**
  * Transfer files from one version to another
  *
  * @return  boolean
  */
 public function transferData($elementparams, $elementId, $pub, $blockParams, $attachments, $oldVersion, $newVersion)
 {
     // Get configs
     $configs = $this->getConfigs($elementparams, $elementId, $pub, $blockParams);
     $newConfigs = new stdClass();
     $newConfigs->path = $configs->path;
     $newConfigs->dataPath = \Components\Publications\Helpers\Html::buildPubPath($pub->id, $newVersion->id, '', 'data', 1);
     $newConfigs->servePath = Route::url('index.php?option=com_publications&id=' . $pub->id) . '/?vid=' . $newVersion->id . '&task=serve';
     // Loop through attachments
     foreach ($attachments as $att) {
         if ($att->type != $this->_name) {
             continue;
         }
         // Get database object and load record
         $objData = new \Components\Projects\Tables\Database($this->_parent->_db);
         $objData->loadRecord($att->object_name);
         $dbVersion = NULL;
         if (!$objData->id) {
             // Original database not found
             $this->_parent->setError(Lang::txt('Oups! Cannot attach selected database: database not found'));
             return false;
         }
         // Make new attachment record
         $pAttach = new \Components\Publications\Tables\Attachment($this->_parent->_db);
         if (!$pAttach->copyAttachment($att, $newVersion->id, $elementId, User::get('id'))) {
             continue;
         }
         // New database instance - need to clone again and get a new version number
         $result = Event::trigger('projects.clone_database', array($pAttach->object_name, $pub->_project, $newConfigs->servePath));
         $dbVersion = $result && isset($result[0]) ? $result[0] : NULL;
         // Failed to clone
         if (!$dbVersion) {
             $this->_parent->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_FAILED_DB_CLONE'));
             $pAttach->delete();
             return false;
         }
         $pAttach->modified_by = NULL;
         $pAttach->modified = NULL;
         $pAttach->object_revision = $dbVersion;
         $pAttach->path = 'dataviewer' . DS . 'view' . DS . 'publication:dsl' . DS . $pAttach->object_name . DS . '?v=' . $dbVersion;
         $pAttach->store();
     }
     // Determine accompanying files and copy them in the right location
     $this->publishDataFiles($objData, $newConfigs);
     return true;
 }
Beispiel #2
0
 /**
  * Transfer files from one version to another
  *
  * @return  boolean
  */
 public function transferData($elementparams, $elementId, $pub, $blockParams, $attachments, $oldVersion, $newVersion)
 {
     // Get configs
     $configs = $this->getConfigs($elementparams, $elementId, $pub, $blockParams);
     // Get configs for new version
     $typeParams = $elementparams->typeParams;
     $directory = isset($typeParams->directory) && $typeParams->directory ? $typeParams->directory : $newVersion->secret;
     $newConfigs = new stdClass();
     // Directory path within pub folder
     $newConfigs->dirPath = $configs->subdir ? $directory . DS . $configs->subdir : $directory;
     // Build new path
     $newPath = \Components\Publications\Helpers\Html::buildPubPath($pub->id, $newVersion->id, '', $newConfigs->dirPath, 1);
     $newConfigs->pubPath = $newPath;
     $newConfigs->dirHierarchy = $configs->dirHierarchy;
     // Create new path
     if (!is_dir($newPath)) {
         Filesystem::makeDirectory($newPath, 0755, true, true);
     }
     // Loop through attachments
     foreach ($attachments as $att) {
         // Make new attachment record
         $pAttach = new \Components\Publications\Tables\Attachment($this->_parent->_db);
         if (!$pAttach->copyAttachment($att, $newVersion->id, $elementId, User::get('id'))) {
             continue;
         }
         // Get paths
         $copyFrom = $this->getFilePath($att->path, $att->id, $configs, $att->params);
         $copyTo = $this->getFilePath($pAttach->path, $pAttach->id, $newConfigs, $pAttach->params);
         if (!is_file($copyFrom)) {
             $pAttach->delete();
             continue;
         }
         // Make sure we have subdirectories
         if (!is_dir(dirname($copyTo))) {
             Filesystem::makeDirectory(dirname($copyTo), 0755, true, true);
         }
         // Copy file
         if (!Filesystem::copy($copyFrom, $copyTo)) {
             $pAttach->delete();
         } else {
             // Also make hash
             $md5hash = hash_file('sha256', $copyTo);
             $pAttach->content_hash = $md5hash;
             // Create hash file
             $hfile = $copyTo . '.hash';
             if (!is_file($hfile)) {
                 $handle = fopen($hfile, 'w');
                 fwrite($handle, $md5hash);
                 fclose($handle);
                 chmod($hfile, 0644);
             }
             $pAttach->store();
             // Produce thumbnail (if applicable)
             if ($configs->handler && $configs->handler->getName() == 'imageviewer') {
                 $configs->handler->makeThumbnail($pAttach, $pub, $newConfigs);
             }
         }
     }
     return true;
 }