Пример #1
0
 public function Delete($mediaId, $newRevisionMediaId = NULL)
 {
     Debug::LogEntry('audit', 'IN', 'Media', 'Delete');
     try {
         $dbh = PDOConnect::init();
         // Check for links
         $sth = $dbh->prepare('SELECT * FROM lklayoutmedia WHERE MediaID = :mediaid');
         $sth->execute(array('mediaid' => $mediaId));
         if ($sth->fetch()) {
             $this->ThrowError(21, __('This media is in use, please retire it instead.'));
         }
         // Get the file name
         $sth = $dbh->prepare('SELECT StoredAs FROM media WHERE mediaID = :mediaid');
         $sth->execute(array('mediaid' => $mediaId));
         if (!($row = $sth->fetch())) {
             $this->ThrowError(22, __('Cannot locate the files for this media. Unable to delete.'));
         }
         // This will be used to delete the actual file (stored on disk)
         $fileName = Kit::ValidateParam($row['StoredAs'], _STRING);
         // Remove permission assignments
         $security = new MediaGroupSecurity($this->db);
         if (!$security->UnlinkAll($mediaId)) {
             throw new Exception("Error Processing Request", 1);
         }
         // Delete any assignments
         $link = new LkMediaDisplayGroup($this->db);
         if (!$link->UnlinkAllFromDisplayGroup($mediaId)) {
             $this->ThrowError(__('Unable to drop file assignments during display delete.'));
         }
         // Delete the media
         $sth = $dbh->prepare('DELETE FROM media WHERE MediaID = :mediaid');
         $sth->execute(array('mediaid' => $mediaId));
         // Delete the file itself (and any thumbs, etc)
         if (!$this->DeleteMediaFile($fileName)) {
             throw new Exception("Error Processing Request", 1);
         }
         // Bring back the previous revision of this media (if there is one)
         $sth = $dbh->prepare('SELECT IFNULL(MediaID, 0) AS MediaID FROM media WHERE EditedMediaID = :mediaid');
         $sth->execute(array('mediaid' => $mediaId));
         if ($editedMediaRow = $sth->fetch()) {
             // Unretire this edited record
             $editedMediaId = Kit::ValidateParam($editedMediaRow['MediaID'], _INT);
             if ($newRevisionMediaId == null) {
                 // Bring back the old one
                 $sth = $dbh->prepare('UPDATE media SET IsEdited = 0, EditedMediaID = NULL WHERE mediaid = :mediaid');
                 $sth->execute(array('mediaid' => $editedMediaId));
             } else {
                 // Link up the old one
                 $sth = $dbh->prepare('UPDATE media SET EditedMediaID = :newRevisionMediaId WHERE mediaid = :mediaid');
                 $sth->execute(array('mediaid' => $editedMediaId, 'newRevisionMediaId' => $newRevisionMediaId));
             }
         }
         return true;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(23, __('Error deleting media.'));
         }
         return false;
     }
 }
Пример #2
0
 /**
  * Associate the list of provided media with this display group
  * @param user $user           The logged in user
  * @param int $displayGroupId The Display Group to Assign to
  * @param array $mediaList      The Media to Assign
  */
 public function AssociateFiles($user, $displayGroupId, $mediaList)
 {
     Debug::LogEntry('audit', 'IN', get_class(), __FUNCTION__);
     Kit::ClassLoader('lkmediadisplaygroup');
     $link = new LkMediaDisplayGroup($this->db);
     try {
         $dbh = PDOConnect::init();
         // Check that some media assignments have been made
         if (count($mediaList) == 0) {
             $this->ThrowError(25006, __('No media to assign'));
         }
         // Drop all current assignments
         if (!$link->UnlinkAllFromDisplayGroup($displayGroupId)) {
             $this->ThrowError(__('Unable to make this assignment during preparation.'));
         }
         // Loop through all the media
         foreach ($mediaList as $mediaId) {
             $mediaId = Kit::ValidateParam($mediaId, _INT);
             // Check we have permissions to use this media (we will use this to copy the media later)
             $mediaAuth = $user->MediaAuth($mediaId, true);
             if (!$mediaAuth->view) {
                 $this->ThrowError(__('You have selected media that you no longer have permission to use. Please reload the form.'));
             }
             // Create the link
             if (!$link->Link($displayGroupId, $mediaId)) {
                 $this->ThrowError(__('Unable to make this assignment'));
             }
         }
         // Flag this display group as incomplete
         $this->FlagIncomplete($displayGroupId);
         return true;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage(), get_class(), __FUNCTION__);
         if (!$this->IsError()) {
             $this->SetError(1, __('Unknown Error'));
         }
         return false;
     }
 }