Exemplo n.º 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);
 }