Example #1
0
 private function _processFileColumns($cols)
 {
     foreach ($cols as $column => $newValue) {
         $oldValue = $this->_attributes[$column];
         if (empty($newValue)) {
             //unset of file column
             if (!empty($oldValue)) {
                 $file = new \GO\Base\Fs\File(GO::config()->file_storage_path . $oldValue);
                 $file->delete();
                 $this->{$column} = "";
             }
         } elseif ($newValue instanceof \GO\Base\Fs\File) {
             if (!isset($this->columns[$column]['filePathTemplate'])) {
                 throw new \Exception('For file columns you must set a filePathTemplate');
             }
             $destination = $this->columns[$column]['filePathTemplate'];
             foreach ($this->_attributes as $key => $value) {
                 $destination = str_replace('{' . $key . '}', $value, $destination);
             }
             $destination = str_replace('{extension}', $newValue->extension(), $destination);
             $destinationFile = new \GO\Base\Fs\File(GO::config()->file_storage_path . $destination);
             $destinationFolder = $destinationFile->parent();
             $destinationFolder->create();
             $newValue->move($destinationFolder, $destinationFile->name());
             $this->{$column} = $destinationFile->stripFileStoragePath();
         } else {
             throw new \Exception("Column {$column} must be an instance of GO\\Base\\Fs\\File. " . var_export($newValue, true));
         }
     }
     return !empty($cols);
 }
Example #2
0
 /**
  * Set new photo file. The file will be converted into JPEG and resized to fit
  * a 480x640 pixel box
  * 
  * @param \GO\Base\Fs\File $file
  */
 public function seOLDPhoto(\GO\Base\Fs\File $file)
 {
     if ($this->isNew) {
         throw new \Exception("Cannot save a photo on a new company that is not yet saved.");
     }
     $this->getPhotoFile()->delete();
     $photoPath = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'company_photos/' . $this->addressbook_id . '/');
     $photoPath->create();
     //		if(strtolower($file->extension())!='jpg'){
     //		$filename = $photoPath->path().'/'.$this->id.'.jpg';
     //		$img = new \GO\Base\Util\Image();
     //		if(!$img->load($file->path())){
     //			throw new \Exception(\GO::t('imageNotSupported','addressbook'));
     //		}
     //
     //		//resize it to small image so we don't get in trouble with sync clients
     //		$img->fitBox(240,320);
     //
     //		if(!$img->save($filename, IMAGETYPE_JPEG)){
     //			throw new \Exception("Could not save photo!");
     //		}
     //		$file = new \GO\Base\Fs\File($filename);
     //		}else
     //		{
     $file->move($photoPath, $this->id . '.' . strtolower($file->extension()));
     //		}
     $this->photo = $file->stripFileStoragePath();
 }
Example #3
0
 protected function actionPluploads($params)
 {
     if (isset($params['addFileStorageFiles'])) {
         $files = json_decode($params['addFileStorageFiles'], true);
         foreach ($files as $filepath) {
             GO::session()->values['files']['uploadqueue'][] = GO::config()->file_storage_path . $filepath;
         }
     }
     $response['results'] = array();
     if (!empty(GO::session()->values['files']['uploadqueue'])) {
         foreach (GO::session()->values['files']['uploadqueue'] as $path) {
             $file = new \GO\Base\Fs\File($path);
             $result = array('human_size' => $file->humanSize(), 'extension' => strtolower($file->extension()), 'size' => $file->size(), 'type' => $file->mimeType(), 'name' => $file->name());
             if ($file->isTempFile()) {
                 $result['from_file_storage'] = false;
                 $result['tmp_file'] = $file->stripTempPath();
             } else {
                 $result['from_file_storage'] = true;
                 $result['tmp_file'] = $file->stripFileStoragePath();
             }
             $response['results'][] = $result;
         }
     }
     $response['total'] = count($response['results']);
     unset(GO::session()->values['files']['uploadqueue']);
     return $response;
 }
Example #4
0
 protected function actionCompress($params)
 {
     ini_set('max_execution_time', 600);
     ini_set('memory_limit', '512M');
     $sources = json_decode($params['compress_sources'], true);
     $workingFolder = \GO\Files\Model\Folder::model()->findByPk($params['working_folder_id']);
     $destinationFolder = \GO\Files\Model\Folder::model()->findByPk($params['destination_folder_id']);
     $archiveFile = new \GO\Base\Fs\File(\GO::config()->file_storage_path . $destinationFolder->path . '/' . $params['archive_name'] . '.zip');
     if ($archiveFile->exists()) {
         throw new \Exception(sprintf(\GO::t('filenameExists', 'files'), $archiveFile->stripFileStoragePath()));
     }
     $sourceObjects = array();
     for ($i = 0; $i < count($sources); $i++) {
         $path = \GO::config()->file_storage_path . $sources[$i];
         $sourceObjects[] = \GO\Base\Fs\Base::createFromPath($path);
     }
     if (\GO\Base\Fs\Zip::create($archiveFile, $workingFolder->fsFolder, $sourceObjects)) {
         \GO\Files\Model\File::importFromFilesystem($archiveFile);
         $response['success'] = true;
     } else {
         throw new \Exception("ZIP creation failed");
     }
     return $response;
 }