Пример #1
0
 /**
  * @return boolean Returns true when successful.
  */
 public function delete()
 {
     // Check dependencies
     Validator::required(isset($this->albumIDs), __METHOD__);
     // Call plugins
     Plugins::get()->activate(__METHOD__, 0, func_get_args());
     // Init vars
     $photoIDs = array();
     // Execute query
     $query = Database::prepare(Database::get(), "SELECT id FROM ? WHERE album IN (?)", array(LYCHEE_TABLE_PHOTOS, $this->albumIDs));
     $photos = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
     if ($photos === false) {
         return false;
     }
     // Only delete photos when albums contain photos
     if ($photos->num_rows > 0) {
         // Add each id to photoIDs
         while ($row = $photos->fetch_object()) {
             $photoIDs[] = $row->id;
         }
         // Convert photoIDs to a string
         $photoIDs = implode(',', $photoIDs);
         // Delete all photos
         $photo = new Photo($photoIDs);
         if ($photo->delete() !== true) {
             return false;
         }
     }
     // Delete albums
     $query = Database::prepare(Database::get(), "DELETE FROM ? WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $this->albumIDs));
     $result = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
     // Call plugins
     Plugins::get()->activate(__METHOD__, 1, func_get_args());
     if ($result === false) {
         return false;
     }
     return true;
 }
Пример #2
0
 /**
  * Deletes a photo with all its data and files.
  * @return boolean Returns true when successful.
  */
 public function delete()
 {
     // Check dependencies
     Validator::required(isset($this->photoIDs), __METHOD__);
     // Call plugins
     Plugins::get()->activate(__METHOD__, 0, func_get_args());
     // Init vars
     $error = false;
     // Get photos
     $query = Database::prepare(Database::get(), "SELECT id, url, thumbUrl, checksum FROM ? WHERE id IN (?)", array(LYCHEE_TABLE_PHOTOS, $this->photoIDs));
     $photos = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
     if ($photos === false) {
         return false;
     }
     // For each photo
     while ($photo = $photos->fetch_object()) {
         // Check if other photos are referring to this images
         // If so, only delete the db entry
         if ($this->exists($photo->checksum, $photo->id) === false) {
             // Get retina thumb url
             $thumbUrl2x = explode(".", $photo->thumbUrl);
             $thumbUrl2x = $thumbUrl2x[0] . '@2x.' . $thumbUrl2x[1];
             // Delete big
             if (file_exists(LYCHEE_UPLOADS_BIG . $photo->url) && !unlink(LYCHEE_UPLOADS_BIG . $photo->url)) {
                 Log::error(Database::get(), __METHOD__, __LINE__, 'Could not delete photo in uploads/big/');
                 $error = true;
             }
             // Delete medium
             if (file_exists(LYCHEE_UPLOADS_MEDIUM . $photo->url) && !unlink(LYCHEE_UPLOADS_MEDIUM . $photo->url)) {
                 Log::error(Database::get(), __METHOD__, __LINE__, 'Could not delete photo in uploads/medium/');
                 $error = true;
             }
             // Delete thumb
             if (file_exists(LYCHEE_UPLOADS_THUMB . $photo->thumbUrl) && !unlink(LYCHEE_UPLOADS_THUMB . $photo->thumbUrl)) {
                 Log::error(Database::get(), __METHOD__, __LINE__, 'Could not delete photo in uploads/thumb/');
                 $error = true;
             }
             // Delete thumb@2x
             if (file_exists(LYCHEE_UPLOADS_THUMB . $thumbUrl2x) && !unlink(LYCHEE_UPLOADS_THUMB . $thumbUrl2x)) {
                 Log::error(Database::get(), __METHOD__, __LINE__, 'Could not delete high-res photo in uploads/thumb/');
                 $error = true;
             }
         }
         // Delete db entry
         $query = Database::prepare(Database::get(), "DELETE FROM ? WHERE id = '?'", array(LYCHEE_TABLE_PHOTOS, $photo->id));
         $result = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
         if ($result === false) {
             $error = true;
         }
     }
     // Call plugins
     Plugins::get()->activate(__METHOD__, 1, func_get_args());
     if ($error === true) {
         return false;
     }
     return true;
 }