Phosphorum\Models\Posts::afterSave PHP Method

afterSave() public method

public afterSave ( )
    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)]);
        }
    }