/**
  * Occurs on element.file.postremove events.
  *
  * @param Event $event
  */
 public function onRemoveElementFile(Event $event)
 {
     $dispatcher = $event->getDispatcher();
     $application = $dispatcher->getApplication();
     try {
         $content = $event->getEventArgs()->getEntity();
         if (!$content instanceof ElementFile) {
             return;
         }
         $includePath = array($application->getStorageDir(), $application->getMediaDir());
         if (null !== $application->getBBUserToken()) {
             $includePath[] = $application->getTemporaryDir();
         }
         $filename = $content->path;
         File::resolveFilepath($filename, null, array('include_path' => $includePath));
         @unlink($filename);
     } catch (\Exception $e) {
         $application->warning('Unable to delete file: ' . $e->getMessage());
     }
 }
Beispiel #2
0
 /**
  * Occur on nestednode.page.preupdate events and nestednode.section.preupdate.
  *
  * @access public
  *
  * @param Event $event
  */
 public function onPreUpdate(Event $event)
 {
     $page = $event->getTarget();
     $eventArgs = $event->getEventArgs();
     $updateParents = false;
     $new = $old = null;
     if ($eventArgs instanceof PreUpdateEventArgs) {
         if ($page instanceof Page && $eventArgs->hasChangedField('_section')) {
             $old = $eventArgs->getOldValue('_section');
             $new = $eventArgs->getNewValue('_section');
             if ($new->getUid() === $page->getUid()) {
                 return;
             }
             $updateParents = true;
         }
         if ($page instanceof Page && $eventArgs->hasChangedField('_state')) {
             if ($page->getParent() !== null) {
                 if ($eventArgs->getNewValue('_state') >= 4) {
                     $old = $page->getParent()->getSection();
                 } else {
                     $new = $page->getParent()->getSection();
                 }
                 $updateParents = true;
             }
         }
         if ($page instanceof Section && $eventArgs->hasChangedField('_parent')) {
             $old = $eventArgs->getOldValue('_parent');
             $new = $eventArgs->getNewValue('_parent');
             $updateParents = true;
         }
         if ($updateParents) {
             self::setSectionHasChildren($old, -1);
             self::setSectionHasChildren($new, +1);
         }
     }
 }