/** * Removes Image (From Cloud) * * @param string $passkey * @param int $intImageId * @return string * @throws SoapFault * @soap */ public function remove_image($passkey, $intImageId) { self::check_passkey($passkey); //Find item in Cloud Image table $objImageCloud = ImagesCloud::model()->findByAttributes(array('cloud_image_id' => $intImageId)); if ($objImageCloud) { $intCloudId = $objImageCloud->image_id; $objImageCloud->delete(); //Find item in Images table $model = Images::model()->findByPk($intCloudId); $model->delete(); //we have to delete() instead of DeleteByPk since beforeDelete() needs to fire } return self::OK; }
/** * Before a delete of an Image record, take appropriate action * @return bool */ public function beforeDelete() { // Null all FK references from Product to this Image. Product::model()->updateAll(array('image_id' => null), 'image_id = :image_id', array(':image_id' => $this->id)); // Delete images where this image is the parent. if ($this->IsPrimary() === true) { $arrChildImages = Images::model()->findAllByAttributes(array('parent' => $this->id)); foreach ($arrChildImages as $objImage) { if ($objImage->id === $this->id) { // For primary images, they are actually their own parent. // Without this check, we'd have an infinite loop. continue; } $objImage->delete(); } } // Delete all ImagesCloud rows that reference this Image to satisfy // foreign key constraints. $arrImagesCloud = ImagesCloud::model()->findAllByAttributes(array('image_id' => $this->id)); foreach ($arrImagesCloud as $objImagesCloud) { $objImagesCloud->delete(); } // Delete the image from the file system. $this->DeleteImage(); return parent::beforeDelete(); }
public function updateCloudId($event, $imageId) { //Find or create a Cloud ID record if we have it if (isset($event->cloud_image_id)) { $objImageCloud = ImagesCloud::model()->findByAttributes(array('image_id' => $imageId)); if (!$objImageCloud instanceof ImagesCloud) { $objImageCloud = new ImagesCloud(); $objImageCloud->image_id = $imageId; } $objImageCloud->cloud_image_id = $event->cloud_image_id; $objImageCloud->cloudinary_public_id = $event->cloudinary_public_id; $objImageCloud->cloudinary_cloud_name = $event->cloudinary_cloud_name; $objImageCloud->cloudinary_version = $event->cloudinary_version; if (!$objImageCloud->save()) { Yii::log("Error updating ImageCloud " . print_r($objImageCloud->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); } } }