Habari\Post::insert PHP Метод

insert() публичный Метод

Saves a new post to the posts table
public insert ( ) : integer | null
Результат integer | null The new post id on success, or false on failure
    public function insert()
    {
        $this->newfields['updated'] = DateTime::create();
        $this->newfields['modified'] = $this->newfields['updated'];
        $this->setguid();
        // if the date is in the future and we are trying to publish the post, actually schedule it for posting later
        if ($this->pubdate > DateTime::create() && $this->status == Post::status('published')) {
            $this->status = Post::status('scheduled');
        } else {
            if ($this->pubdate <= DateTime::create() && $this->status == Post::status('scheduled')) {
                $this->status = Post::status('published');
            }
        }
        $allow = true;
        $allow = Plugins::filter('post_insert_allow', $allow, $this);
        if (!$allow) {
            return false;
        }
        Plugins::act('post_insert_before', $this);
        // Invoke plugins for all fields, since they're all "changed" when inserted
        foreach ($this->fields as $fieldname => $value) {
            $fieldvalue = isset($this->newfields[$fieldname]) ? $this->newfields[$fieldname] : $this->fields[$fieldname];
            Plugins::act('post_update_' . $fieldname, $this, $this->id == 0 ? null : $value, $fieldvalue);
        }
        // invoke plugins for status changes
        Plugins::act('post_status_' . self::status_name($this->status), $this, null);
        $result = parent::insertRecord('posts', $this->get_schema_map());
        $this->newfields['id'] = $result;
        // Make sure the id is set in the post object to match the row id
        $this->fields = array_merge($this->fields, $this->newfields);
        $this->newfields = array();
        $this->info->commit(DB::last_insert_id());
        $this->save_tags();
        // This fires __call() which dispatches to any plugins on action_post_call_create_default_permissions()
        $this->create_default_permissions();
        $this->create_default_tokens();
        EventLog::log(_t('New post %1$s (%2$s);  Type: %3$s; Status: %4$s', array($this->id, $this->slug, Post::type_name($this->content_type), $this->statusname)), 'info', 'content', 'habari');
        Plugins::act('post_insert_after', $this);
        //scheduled post
        if ($this->status == Post::status('scheduled')) {
            Posts::update_scheduled_posts_cronjob();
        }
        return $result;
    }