/** * * @param Picture $picture_ * @throws InvalidArgumentException */ public function updatePicture(Picture $picture_) { try { if (isset($this->table) && is_null($this->table)) { throw new InvalidArgumentException('Attribute "table" can\'t be NULL !'); } if (isset($this->id) && !is_null($this->id)) { $where = 'id = ' . $this->id; } //Existance test $picture = $this->selectPicture(); if (!emptyObjectMethod($picture)) { $picture = $this->selectPicture(); $path = $picture->getPath(); $title = $picture->getTitle(); $ext = $picture->getExtension(); if (file_exists(UPLOAD_PATH . $path . $title . '.' . $ext)) { if (!is_null($picture_->getTitle()) && $title !== $picture_->getTitle()) { if (!rename(UPLOAD_PATH . $path . $title . '.' . $ext, UPLOAD_PATH . $path . $picture_->getTitle() . '.' . $ext)) { throw new Exception('A problem occurred when renaming !'); } } } } else { throw new Exception('Picture doesn\'t exist !'); } return parent::update($this->table, $picture_, $where); } catch (InvalidArgumentException $e) { print $e->getMessage(); exit; } catch (Exception $e) { print $e->getMessage(); exit; } }