Beispiel #1
0
    protected function saveDBData()
    {
        $this->updatePost();
        $modified = $this->post->isModified();
        // save the post
        $this->post->save();
        // save tags
        $tags = $this->getTags();
        $result = $this->post->setTagsByShortName($tags);
        $tags_modified = $result['added'] > 0 || $result['removed'] > 0;
        $modified = $modified || $tags_modified;
        $instance_id = $this->app->getInstanceId();
        // update files attached to the form to be attached to the post
        if ($this->id === null) {
            $form = $this->ui->getWidget('edit_form');
            $unique_id = $form->getHiddenField('unique_id');
            $sql = sprintf('update BlorgFile set post = %s,
				form_unique_id = null
				where form_unique_id = %s and post is null
					and instance %s %s', $this->app->db->quote($this->post->id, 'integer'), $this->app->db->quote($unique_id, 'text'), SwatDB::equalityOperator($instance_id), $this->app->db->quote($instance_id, 'integer'));
            $num = SwatDB::exec($this->app->db, $sql);
            $modified = $modified || $num > 0;
        }
        if ($modified) {
            // clear cache
            if (isset($this->app->memcache)) {
                $this->app->memcache->flushNs('posts');
                $old_date = $this->original_publish_date;
                $new_date = $this->post->publish_date;
                if ($old_date instanceof SwatDate && $new_date instanceof SwatDate) {
                    $date_modified = SwatDate::compare($old_date, $new_date) !== 0;
                } elseif ($old_date instanceof SwatDate && $new_date === null) {
                    $date_modified = true;
                } elseif ($old_date === null && $new_date instanceof SwatDate) {
                    $date_modified = true;
                } else {
                    $date_modified = $old_date !== $new_date;
                }
                if ($this->original_enabled !== $this->post->enabled || $date_modified || $tags_modified) {
                    $this->app->memcache->flushNs('tags');
                }
            }
            $this->addToSearchQueue();
            $message = new SwatMessage(sprintf(Blorg::_('“%s” has been saved.'), $this->post->getTitle()));
            // ping weblogs
            if ($this->post->enabled && $this->pingWeblogsDotCom()) {
                $message->secondary_content = Blorg::_('Weblogs.com has been notified of updated content.');
            }
            $this->app->messages->add($message);
        }
    }