Example #1
0
 /**
  * Hook called when a page's has been changed and saved
  *
  * Previous status may be accessed at $page->statusPrevious
  *
  * @param Page $page 
  *
  */
 public function ___statusChanged(Page $page)
 {
     $status = $page->status;
     $statusPrevious = $page->statusPrevious;
     $isPublished = !$page->isUnpublished();
     $wasPublished = !($statusPrevious & Page::statusUnpublished);
     if ($isPublished && !$wasPublished) {
         $this->published($page);
     }
     if (!$isPublished && $wasPublished) {
         $this->unpublished($page);
     }
     $from = array();
     $to = array();
     foreach (Page::getStatuses() as $name => $flag) {
         if ($flag == Page::statusUnpublished) {
             continue;
         }
         // logged separately
         if ($statusPrevious & $flag) {
             $from[] = $name;
         }
         if ($status & $flag) {
             $to[] = $name;
         }
     }
     if (count($from) || count($to)) {
         $added = array();
         $removed = array();
         foreach ($from as $name) {
             if (!in_array($name, $to)) {
                 $removed[] = $name;
             }
         }
         foreach ($to as $name) {
             if (!in_array($name, $from)) {
                 $added[] = $name;
             }
         }
         $str = '';
         if (count($added)) {
             $str = "Added status '" . implode(', ', $added) . "'";
         }
         if (count($removed)) {
             if ($str) {
                 $str .= ". ";
             }
             $str .= "Removed status '" . implode(', ', $removed) . "'";
         }
         if ($str) {
             $this->log($str, $page);
         }
     }
 }