public function executeRemovePhoto(sfWebRequest $request) { $c = new Criteria(); $c->add(MissionPhotoPeer::ID, $request->getParameter('id')); $photos = MissionPhotoPeer::doSelect($c); $ad_photo = $photos[0]->getPhotoFilename(); $img_dir = sfConfig::get('sf_upload_dir') . '/mission_photo/display/'; $img_thmb = sfConfig::get('sf_upload_dir') . '/mission_photo/thumbnails/'; //unlink function return bool so you can use it as conditon if (@unlink($img_dir . $ad_photo) && @unlink($img_thmb . $ad_photo)) { $c->add(MissionPhotoPeer::PHOTO_FILENAME, ''); MissionPhotoPeer::doUpdate($c); } $this->redirect("mission_photo/show?id=" . $request->getParameter('id')); }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aMission !== null) { if ($this->aMission->isModified() || $this->aMission->isNew()) { $affectedRows += $this->aMission->save($con); } $this->setMission($this->aMission); } if ($this->aMissionLeg !== null) { if ($this->aMissionLeg->isModified() || $this->aMissionLeg->isNew()) { $affectedRows += $this->aMissionLeg->save($con); } $this->setMissionLeg($this->aMissionLeg); } if ($this->isNew()) { $this->modifiedColumns[] = MissionPhotoPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = MissionPhotoPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += MissionPhotoPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }