Example #1
0
 /**
  * Transfer files from one version to another
  *
  * @param      string  $sourceid Source version ID
  * @param      string  $destid   Destination version ID
  * @param      integer $rid      Resource ID
  * @return     boolean False if errors, True on success
  */
 public function transfer($sourceid, $destid, $rid)
 {
     Log::debug(__FUNCTION__ . '()');
     // Get resource information
     $resource = new \Components\Resources\Tables\Resource($this->database);
     $resource->load($rid);
     // Get screenshot information
     $ss = new \Components\Resources\Tables\Screenshot($this->database);
     $shots = $ss->getFiles($rid, $sourceid);
     // Build the path
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php';
     $listdir = \Components\Resources\Helpers\Html::build_path($resource->created, $rid, '');
     $srcdir = $listdir . DS . $sourceid;
     $destdir = $listdir . DS . $destid;
     $src = $this->_buildUploadPath($srcdir, '');
     $dest = $this->_buildUploadPath($destdir, '');
     // Make sure the path exist
     if (!is_dir($src)) {
         if (!Filesystem::makeDirectory($src)) {
             $this->setError(Lang::txt('COM_TOOLS_UNABLE_TO_CREATE_UPLOAD_PATH'));
             return false;
         }
     }
     Log::debug(__FUNCTION__ . "() {$src}");
     // do we have files to transfer?
     $files = Filesystem::files($src, '.', false, true, array());
     Log::debug(__FUNCTION__ . "() " . implode(',', $files));
     if (!empty($files)) {
         // Copy directory
         Log::debug(__FUNCTION__ . "() copying {$src} to {$dest}");
         if (!Filesystem::copyDirectory($src, $dest, '', true)) {
             return false;
         } else {
             // Update screenshot information for this resource
             $ss->updateFiles($rid, $sourceid, $destid, $copy = 1);
             Log::debug(__FUNCTION__ . '() updated files');
             return true;
         }
     }
     Log::debug(__FUNCTION__ . '() done');
     return true;
 }