@param Blog  $blog
@param array $changeSet

@return Controller
195935
public function dispatchBlogUpdateEvent(Blog $blog, $changeSet)
    {
        $logEvent = new LogResourceUpdateEvent($blog->getResourceNode(), $changeSet);

        return $this->dispatch($logEvent);
    }
1330306
public function findCalendarDatas(Blog $blog, $startDate, $endDate, $executeQuery = true)
    {
        $startDateTime = new \DateTime($startDate);
        $currentTimestamp = time();
        $endDateTime = new \DateTime($endDate);

        if ($currentTimestamp < $endDate) {
            $endDateTime->setTimestamp($currentTimestamp);
        }

        $query = $this->createQueryBuilder('post')
            ->select(['post'])
            ->andWhere('post.blog = :blogId')
            ->andWhere('post.status = :postStatus')
            ->andWhere('post.publicationDate IS NOT NULL')
            ->andWhere('post.publicationDate BETWEEN :startDate AND :endDate')
            ->setParameter('blogId', $blog->getId())
            ->setParameter('postStatus', Statusable::STATUS_PUBLISHED)
            ->setParameter('startDate', $startDateTime)
            ->setParameter('endDate', $endDateTime)
            ->getQuery()
        ;

        return $executeQuery ? $query->getResult() : $query;
    }
1149231
public function getAll($excludeUnpublished = false, Blog $blog = null)
    {
        $this->clearInstance();
        $this->qb = $this->getInstance();

        //If $excludeUnpublished === true, we exclude the non published results
        if ($excludeUnpublished) {
            $this->qb
                ->andWhere('article.status = :status')
                ->orWhere('article.status = :scheduled_status AND article.publishedAt <= :now')
                ->setParameter('status', PageStatus::PUBLISHED)
                ->setParameter('scheduled_status', PageStatus::SCHEDULED)
                ->setParameter('now', new \DateTime());
        }

        if (null != $blog) {
            $this->qb
                ->andWhere('article.blog = :blog')
                ->setParameter('blog', $blog->getId());
        }

        return $this;
    }
470485
public function dispatchCommentUpdateEvent(Post $post, Comment $comment, $changeSet)
    {
        $event = new LogCommentUpdateEvent($post, $comment, $changeSet, $this->translator);

        return $this->dispatch($event);
    }
1127308
public function getPostByIdOrSlug(Blog $blog, $postId)
    {
        if (is_int($postId)) {
            $post = $this->repo->findOneBy([
                'blog' => $blog,
                'id' => $postId,
            ]);
        } else {
            $post = $this->repo->findOneBy([
                'blog' => $blog,
                'slug' => $postId,
            ]);
        }

        return $post;
    }
123043
public function changeAction(ChangeCollection $changes)
    {
        try {
            $count = $changes->count();
            $changes->apply();

            $success = new Info();
            $success->setMessage(sprintf('%d change(s) successfully applied.', $count));

            $this->feedbackCollection->add($success);
            $this->persistenceManager->persistAll();
        } catch (\Exception $e) {
            $error = new Error();
            $error->setMessage($e->getMessage());

            $this->feedbackCollection->add($error);
        }

        $this->view->assign('value', $this->feedbackCollection);
    }
750041
public function getOptionsAction(Request $request, Blog $blog)
    {
        $this->checkPermission('EDIT', $blog->getResourceNode(), [], true);

        return new JsonResponse($this->blogOptionsSerializer->serialize($blog, $blog->getOptions(), $this->blogManager->getPanelInfos()));
    }
593950
private function getChangesGroupedByNsPredicate(\Tripod\ChangeSet $cs, $changeUri, $changePredicate)
    {
        $changes = $cs->get_subject_property_values($changeUri,$changePredicate);

        $changesGroupedByNsPredicate = array();
        foreach ($changes as $c)
        {
            $predicate = $cs->get_first_resource($c["value"],$this->labeller->qname_to_uri("rdf:predicate"));
            $nsPredicate = $this->labeller->uri_to_qname($predicate);

            if(!array_key_exists($nsPredicate, $changesGroupedByNsPredicate))
            {
                $changesGroupedByNsPredicate[$nsPredicate] = array();
            }

            $object = $cs->get_subject_property_values($c["value"],$this->labeller->qname_to_uri("rdf:object"));
            if (count($object)!=1)
            {
                $this->getLogger()->error("Expecting object array with exactly 1 element",$object);
                throw new \Tripod\Exceptions\Exception("Object of removal malformed");
            }

            $valueType = (($object[0]['type']=="uri")) ? VALUE_URI : VALUE_LITERAL;
            $value = ($valueType===VALUE_URI) ? $this->labeller->uri_to_alias($object[0]["value"]) : $object[0]["value"];

            $changesGroupedByNsPredicate[$nsPredicate][] = array($valueType=>$value);
        }
        return $changesGroupedByNsPredicate;
    }
1172463
function switch_to_blog( $blog_id, FS_Site $install = null ) {
            if ( $blog_id == $this->_context_is_network_or_blog_id ) {
                return;
            }

            switch_to_blog( $blog_id );
            $this->_context_is_network_or_blog_id = $blog_id;

            self::$_accounts->set_site_blog_context( $blog_id );
            $this->_storage->set_site_blog_context( $blog_id );
            $this->_storage->set_network_active( $this->_is_network_active, $this->is_delegated_connection( $blog_id ) );

            $this->_site = is_object( $install ) ?
                $install :
                $this->get_install_by_blog_id( $blog_id );

            $this->_user     = false;
            $this->_licenses = false;
            $this->_license  = null;

            if ( is_object( $this->_site ) ) {
                // Try to fetch user from install.
                $this->_user = self::_get_user_by_id( $this->_site->user_id );

                if ( ! is_object( $this->_user ) &&
                     FS_User::is_valid_id( $this->_storage->prev_user_id )
                ) {
                    // Try to fetch previously saved user.
                    $this->_user = self::_get_user_by_id( $this->_storage->prev_user_id );

                    if ( ! is_object( $this->_user ) ) {
                        // Fallback to network's user.
                        $this->_user = $this->get_network_user();
                    }
                }

                $all_plugin_licenses = self::get_all_licenses( $this->_module_id );

                if ( ! empty( $all_plugin_licenses ) ) {
                    if ( ! FS_Plugin_License::is_valid_id( $this->_site->license_id ) ) {
                        $this->_license = null;
                    } else {
                        $license_found = false;
                        foreach ( $all_plugin_licenses as $license ) {
                            if ( $license->id == $this->_site->license_id ) {
                                // License found.
                                $this->_license = $license;
                                $license_found  = true;
                                break;
                            }
                        }

                        if ( $license_found ) {
                            $this->link_license_2_user( $this->_license->id, $this->_user->id );
                        }
                    }

                    $this->_licenses = $this->get_user_licenses( $this->_user->id );
                }
            }

            unset( $this->_site_api );
            unset( $this->_user_api );
        }
227699
public function createComment(Blog $blog, Post $post, Comment $comment, $forcePublication = false)
    {
        $published = false;
        if ($blog->isAutoPublishComment()
            || $forcePublication
            || (BlogOptions::COMMENT_MODERATION_PRIOR_ONCE === $blog->getOptions()->getCommentModerationMode()
                && null !== $comment->getAuthor()
                && count($this->memberRepo->getTrustedMember($blog, $comment->getAuthor())) >= 1)) {
            $published = true;
        }

        $comment
            ->setPost($post)
            ->setStatus($published ? Comment::STATUS_PUBLISHED : Comment::STATUS_UNPUBLISHED);

        if (null === $comment->getCreationDate()) {
            $comment->setCreationDate(new \DateTime());
        }

        $this->om->persist($comment);
        $this->om->flush();

        $this->trackingManager->dispatchCommentCreateEvent($post, $comment);

        if (null !== $comment->getAuthor()) {
            $this->trackingManager->updateResourceTracking($blog->getResourceNode(), $comment->getAuthor(), new \DateTime());
        }

        return $comment;
    }
1054356
public function get($blogId, $articleId, array $fields = array())
    {
        $params = array();
        if (!empty($fields)) {
            $params['fields'] = implode(',', $fields);
        }
        $endpoint = '/admin/blogs/'.$blogId.'/articles/'.$articleId.'.json';
        $response = $this->request($endpoint, 'GET', $params);
        return $this->createObject(Article::class, $response['article']);
    }
935859
public function create(Blog &$blog)
    {
        $data = $blog->exportData();
        $endpoint = '/admin/blogs.json';
        $response = $this->request(
            $endpoint, 'POST', array(
            'blog' => $data
            )
        );
        $blog->setData($response['blog']);
    }
986552
public function create()
    {
        if (!userHasPermission('admin:blog:blog:create')) {

            unauthorised();
        }

        // --------------------------------------------------------------------------

        $this->data['page']->title = 'Manage Blogs &rsaquo; Create';

        // --------------------------------------------------------------------------

        //  Handle POST
        if ($this->input->post()) {

            $oFormValidation = Factory::service('FormValidation');
            $oFormValidation->set_rules('label', '', 'required');
            $oFormValidation->set_rules('description', '', '');
            $oFormValidation->set_message('required', lang('fv_required'));

            if ($oFormValidation->run()) {

                $aInsertData                = array();
                $aInsertData['label']       = $this->input->post('label');
                $aInsertData['description'] = $this->input->post('description');

                $iId = $this->blog_model->create($aInsertData);

                if ($iId) {

                    $sStatus   = 'success';
                    $sMessage  = 'Blog was created successfully, ';
                    $sMessage .= 'now please confirm blog settings.';
                    $this->session->set_flashdata($sStatus, $sMessage);
                    redirect('admin/blog/settings?blog_id=' . $iId);

                } else {

                    $this->data['error']  = 'Failed to create blog. ';
                    $this->data['error'] .= $this->blog_model->lastError();
                }

            } else {

                $this->data['error'] = lang('fv_there_were_errors');
            }
        }

        // --------------------------------------------------------------------------

        //  Load views
        Helper::loadView('edit');
    }
275893
public function updatePost(Blog $blog, Post $existingPost, Post $post, User $user)
    {
        $existingPost
        ->setTitle($post->getTitle())
        ->setContent($post->getContent());
        if (null !== $post->getPublicationDate()) {
            $existingPost->setPublicationDate($post->getPublicationDate());
        } else {
            $existingPost->setPublicationDate(null);
        }

        $this->om->flush();

        $unitOfWork = $this->om->getUnitOfWork();
        $unitOfWork->computeChangeSets();
        $changeSet = $unitOfWork->getEntityChangeSet($existingPost);

        $this->trackingManager->dispatchPostUpdateEvent($existingPost, $changeSet);

        if ('anon.' !== $user) {
            $this->trackingManager->updateResourceTracking($blog->getResourceNode(), $user, new \DateTime());
        }

        return $existingPost;
    }
924211
public function getArticles(Blog $blog)
    {
        $queryBuilder = $this->getAll(false, $blog)
            ->getInstance();

        return $queryBuilder
            ->andWhere('article.status IN (:status)')
            ->setParameter('status', [
                PageStatus::PUBLISHED,
                PageStatus::SCHEDULED,
                PageStatus::UNPUBLISHED,
            ])
            ->orderBy('article.publishedAt', 'DESC')
            ->getQuery()
            ->getResult();
    }
995960
public function changelog($revision1, $revision2)
    {
        $this->fetch();

        return $this->execute('log', array(
                '--pretty=' => self::PRETTY_FORMAT,
                sprintf('%s^1..%s', $revision1, $revision2),
            )
        );
    }
66109
public function show(BlogRequest $request, Blog $blog)
    {

        if ($blog->exists) {
            $view = 'blog::blog.show';
        } else {
            $view = 'blog::blog.new';
        }

        return $this->response->title(trans('app.view') . ' ' . trans('blog::blog.name'))
            ->data(compact('blog'))
            ->view($view, true)
            ->output();
    }