Beispiel #1
0
 public function afterSave()
 {
     $this->clearCache();
     $history = new PostsHistory();
     $history->posts_id = $this->id;
     $history->users_id = $this->getDI()->getSession()->get('identity');
     $history->content = $this->content;
     $history->save();
 }
Beispiel #2
0
 public function afterSave()
 {
     $this->clearCache();
     // In case of updating post through creating PostsViews
     if (!$this->getDI()->getShared('session')->has('identity')) {
         return;
     }
     $history = new PostsHistory(['posts_id' => $this->id, 'users_id' => $this->getDI()->getShared('session')->get('identity'), 'content' => $this->content]);
     if (!$history->save()) {
         /** @var \Phalcon\Logger\AdapterInterface $logger */
         $logger = $this->getDI()->get('logger');
         $messages = $history->getMessages();
         $reason = [];
         foreach ($messages as $message) {
             /** @var \Phalcon\Mvc\Model\MessageInterface $message */
             $reason[] = $message->getMessage();
         }
         $logger->error('Unable to store post history. Post id: {id}. Reason: {reason}', ['id' => $this->id, 'reason' => implode('. ', $reason)]);
     }
 }