コード例 #1
0
ファイル: exif.php プロジェクト: netbiel/core
 /**
  * Creates or updates the current exif data
  *
  * If $key is passed, the record will be assumed to exist
  * and an update will be executed, even if the model isn't loaded().
  *
  * @param   mixed  $key
  * @return  $this
  */
 public function save($key = null)
 {
     // If new EXIF data, try to read from image
     if (!$this->loaded() && !$key) {
         $this->read();
     }
     // If was new and no exif data was found it will not be saved
     parent::save($key);
 }
コード例 #2
0
ファイル: supply.php プロジェクト: TdroL/hurtex
 public function save($key = NULL)
 {
     if ($this->product->unit->type == 'integer') {
         $this->quantity = (int) $this->quantity;
     }
     $status = $this->_original['status'];
     parent::save();
     if ($status != $this->status and $this->status == 'done') {
         $this->product->modify_quantity($this->quantity);
     }
 }
コード例 #3
0
ファイル: product.php プロジェクト: TdroL/hurtex
 public function save($key = NULL)
 {
     parent::save($key);
     try {
         DB::begin();
         DB::delete('product_search')->where('product_id', '=', $this->id)->execute();
         DB::insert('product_search')->values(array('product_id' => $this->id, 'name' => $this->name, 'fulltext' => $this->description))->execute();
         DB::commit();
     } catch (Exception $e) {
         DB::rollback();
     }
     if (!empty($this->_late_update)) {
         foreach ($this->_late_update as $v) {
             list($model, $related, $field) = $v;
             $model->{$related} = $this->{$field};
             $model->save();
         }
     }
 }
コード例 #4
0
ファイル: token.php プロジェクト: netbiel/core
 /**
  * Update user token
  *
  * @return  boolean
  */
 public function update()
 {
     $this->token = $this->create_token();
     return parent::save();
 }
コード例 #5
0
ファイル: token.php プロジェクト: raeldc/jelly-auth
 public function update()
 {
     // Create a new token each time the token is saved
     $this->token = $this->create_token();
     return parent::save();
 }
コード例 #6
0
ファイル: image.php プロジェクト: netbiel/core
 /**
  * Creates or updates the current image
  *
  * If $key is passed, the record will be assumed to exist
  * and an update will be executed, even if the model isn't loaded().
  *
  * @param   mixed  $key
  * @return  $this
  */
 public function save($key = null)
 {
     $new = !$this->loaded() && !$key;
     if ($new) {
         if (!$this->file || !Upload::not_empty($this->file)) {
             throw new Kohana_Exception(__('No image'));
         } else {
             if (!Upload::size($this->file, Kohana::config('image.filesize'))) {
                 throw new Kohana_Exception(__('Image too big (limit :size)', array(':size' => Kohana::config('image.filesize'))));
             } else {
                 if (!Upload::type($this->file, Kohana::config('image.filetypes'))) {
                     throw new Kohana_Exception(__('Invalid image type (use :types)', array(':types' => implode(', ', Kohana::config('image.filetypes')))));
                 }
             }
         }
     }
     parent::save($key);
     // Some magic on created images only
     if ($new) {
         // Make sure we have the new target directory
         $new_path = Kohana::config('image.path') . URL::id($this->id);
         if (!is_dir($new_path)) {
             mkdir($new_path, 0777, true);
             chmod($new_path, 0777);
         }
         if (is_writable($new_path)) {
             $new_path = rtrim($new_path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
         } else {
             throw new Kohana_Exception(get_class($this) . ' can not write to directory');
         }
         // New file name with some random postfix for hard to guess filenames
         !$this->postfix and $this->postfix = Text::random('alnum', 8);
         $new_file = $this->id . '_' . $this->postfix . Kohana::config('image.postfix_original') . '.jpg';
         // Rename and move to correct directory using image id
         $old_path = Kohana::config('image.upload_path');
         $old_file = $this->file;
         if (!rename($old_path . $old_file, $new_path . $new_file)) {
             throw new Kohana_Exception(get_class($this) . ' could not move uploaded image');
         }
         $this->file = $new_file;
         // Start creating images
         $this->_generate_images($new_path . $new_file);
         parent::save();
     }
     return $this;
 }