/**
  * Copies the transport into the vehicle and transforms the payload for storage.
  */
 protected function _compilePayload(& $transport) {
     parent :: _compilePayload($transport);
     $body = array ();
     $cacheManager = $transport->xpdo->getCacheManager();
     if ($cacheManager) {
         if (isset($this->payload['object'])) {
             $object = $this->payload['object'];
             $fileSource = $object['source'];
             $body['source'] = $transport->signature . '/' . $this->payload['class'] . '/' . $this->payload['signature'] . '/';
             $fileTarget = $transport->path . $body['source'];
             $body['target'] = $object['target'];
             $fileName = isset ($object['name']) ? $object['name'] : basename($fileSource);
             $body['name'] = $fileName;
             if (!is_writable($fileTarget)) {
                 $cacheManager->writeTree($fileTarget);
             }
             if (file_exists($fileSource) && is_writable($fileTarget)) {
                 $copied = false;
                 if (is_file($fileSource)) {
                     $copied = $cacheManager->copyFile($fileSource, $fileTarget . $fileName);
                 }
                 if (!$copied) {
                     $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not copy file from {$fileSource} to {$fileTarget}{$fileName}");
                     $body = null;
                 }
             } else {
                 $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Source file {$fileSource} is missing or {$fileTarget} is not writable");
                 $body = null;
             }
         }
     }
     if (!empty($body)) {
         $this->payload['object'] = $body;
     }
 }
Exemplo n.º 2
0
 /**
  * Copies the files into the vehicle and transforms the payload for storage.
  */
 protected function _compilePayload(&$transport)
 {
     \xPDOVehicle::_compilePayload($transport);
     if (isset($this->payload['object']['in']) && isset($this->payload['object']['target'])) {
         $fs = new Filesystem();
         $rootFolder = explode('/', $this->payload['object']['in']);
         $rootFolder = array_pop($rootFolder);
         $this->payload['object']['name'] = $rootFolder;
         $this->payload['object']['source'] = $transport->signature . '/' . $this->payload['class'] . '/' . $this->payload['signature'];
         $filePath = $transport->path . $transport->signature . '/' . $this->payload['class'] . '/' . $this->payload['signature'] . '/' . $rootFolder;
         $fs->mkdir($filePath);
         /** @var SplFileInfo $file */
         foreach ($this->payload['object']['files'] as $file) {
             if ($file->isDir()) {
                 $fs->mkdir($filePath . '/' . $file->getRelativePathname());
             } else {
                 $fs->copy($file->getRealpath(), $filePath . '/' . $file->getRelativePathname());
             }
         }
         unset($this->payload['object']['files']);
     }
 }
 /**
  * Copies the files into the vehicle and transforms the payload for storage.
  */
 protected function _compilePayload(&$transport)
 {
     parent::_compilePayload($transport);
     $body = array();
     $cacheManager = $transport->xpdo->getCacheManager();
     if ($cacheManager) {
         if (isset($this->payload['object'])) {
             $object = $this->payload['object'];
             $fileSource = $object['source'];
             $scriptName = basename($fileSource, '.php');
             $body['source'] = $transport->signature . '/' . $this->payload['class'] . '/' . $this->payload['signature'] . '.' . $scriptName . '.script';
             $fileTarget = $transport->path . $body['source'];
             $body = array_merge($object, $body);
             if (!$cacheManager->copyFile($fileSource, $fileTarget)) {
                 $transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Source file {$fileSource} is missing or {$fileTarget} could not be written");
                 $body = null;
             }
         }
     }
     if (!empty($body)) {
         $this->payload['object'] = $body;
     }
 }