Commit 8e0eb842 authored by Guy Thouret's avatar Guy Thouret Committed by Mark Harding
Browse files

Resolve "(bug): publishing a blog that was saved as a draft or "unlisted" does...

Resolve "(bug): publishing a blog that was saved as a draft or "unlisted" does not generate activity post"
parent c8fc5942
Loading
Loading
Loading
Loading

Common/Access.php

0 → 100644
+22 −0
Original line number Original line Diff line number Diff line
<?php

namespace Minds\Common;

class Access
{
    const UNLISTED = 0;
    const LOGGED_IN = 1;
    const PUBLIC = 2;
    const UNKNOWN = 99;

    const ACCESS_STRINGS = [
        0 => 'Unlisted',
        1 => 'LoggedIn',
        3 => 'Public'
    ];

    public static function idToString(int $id) : string
    {
        return self::ACCESS_STRINGS[$id] ?? 'Unknown';
    }
}
+14 −21
Original line number Original line Diff line number Diff line
@@ -10,8 +10,8 @@ namespace Minds\Controllers\api\v1;


use Minds\Api\Exportable;
use Minds\Api\Exportable;
use Minds\Api\Factory;
use Minds\Api\Factory;
use Minds\Common\Access;
use Minds\Core;
use Minds\Core;
use Minds\Entities\Activity;
use Minds\Helpers;
use Minds\Helpers;
use Minds\Interfaces;
use Minds\Interfaces;


@@ -93,7 +93,7 @@ class blog implements Interfaces\Api
                
                
                $export = [];
                $export = [];
                foreach ($blogs as $blog) {
                foreach ($blogs as $blog) {
                    if ($blog->getOwnerGuid() != Core\Session::getLoggedInUserGuid() && $blog->getAccessId() != 2) {
                    if ($blog->getOwnerGuid() != Core\Session::getLoggedInUserGuid() && $blog->getAccessId() != Access::PUBLIC) {
                        continue;
                        continue;
                    }
                    }
                    $export[] = $blog;
                    $export[] = $blog;
@@ -157,13 +157,16 @@ class blog implements Interfaces\Api
        $header = new Core\Blogs\Header();
        $header = new Core\Blogs\Header();


        $response = [];
        $response = [];
        $alreadyPublished = false;
        $oldAccessId = Access::UNKNOWN;


        $editing = isset($pages[0]) && (is_numeric($pages[0]) || Core\Luid::isValid($pages[0]));
        $editing = isset($pages[0]) && (is_numeric($pages[0]) || Core\Luid::isValid($pages[0]));


        if ($editing) {
        if ($editing) {
            $blog = $manager->get($pages[0]);
            $blog = $manager->get($pages[0]);


            $originallyPublished = $blog->isPublished();
            $alreadyPublished = $blog->isPublished();
            $oldAccessId = $alreadyPublished ? $blog->getAccessId() : $blog->getDraftAccessId();
        } else {
        } else {
            $blog = new Core\Blogs\Blog();
            $blog = new Core\Blogs\Blog();
            $blog
            $blog
@@ -218,7 +221,8 @@ class blog implements Interfaces\Api
        }
        }


        if (isset($_POST['published'])) {
        if (isset($_POST['published'])) {
            $blog->setPublished(!!$_POST['published']);
            $published = is_string($_POST['published']) ? json_decode($_POST['published']) : $_POST['published'];
            $blog->setPublished($published);
        }
        }


        if (isset($_POST['monetized'])) {
        if (isset($_POST['monetized'])) {
@@ -237,9 +241,8 @@ class blog implements Interfaces\Api
            }
            }
        }
        }


        //draft
        if (!$blog->isPublished()) {
        if (!$_POST['published'] || $_POST['published'] === 'false') {
            $blog->setAccessId(Access::UNLISTED);
            $blog->setAccessId(0);
            $blog->setDraftAccessId($_POST['access_id']);
            $blog->setDraftAccessId($_POST['access_id']);
        } elseif ($blog->getTimePublished() == '') {
        } elseif ($blog->getTimePublished() == '') {
            $blog->setTimePublished(time());
            $blog->setTimePublished(time());
@@ -282,7 +285,6 @@ class blog implements Interfaces\Api
            }
            }
        }
        }



        if (isset($_POST['mature']) && $_POST['mature']) {
        if (isset($_POST['mature']) && $_POST['mature']) {
            $user = Core\Session::getLoggedInUser();
            $user = Core\Session::getLoggedInUser();


@@ -333,20 +335,11 @@ class blog implements Interfaces\Api
        if ($saved) {
        if ($saved) {
            $createActivity = new Core\Blogs\Delegates\CreateActivity();
            $createActivity = new Core\Blogs\Delegates\CreateActivity();


            if (
            if ($blog->isPublished() && $blog->getAccessId() == Access::PUBLIC) {
                !$editing &&
                if (!$editing || ($editing && !$alreadyPublished) || ($editing && $oldAccessId == Access::UNLISTED)) {
                $blog->isPublished() &&
                $blog->getAccessId() == 2
            ) {
                $createActivity->save($blog);
            } elseif (
                $editing &&
                !$originallyPublished &&
                $blog->isPublished() &&
                $blog->getAccessId() == 2
            ) {
                    $createActivity->save($blog);
                    $createActivity->save($blog);
                }
                }
            }


            $response['guid'] = (string) $blog->getGuid();
            $response['guid'] = (string) $blog->getGuid();
            $response['slug'] = $blog->getSlug();
            $response['slug'] = $blog->getSlug();
+19 −0
Original line number Original line Diff line number Diff line
<?php

namespace Spec\Minds\Common;

use Minds\Common\Access;
use PhpSpec\ObjectBehavior;

class AccessSpec extends ObjectBehavior
{
    public function it_should_return_string_for_an_access_id()
    {
        $this::idToString(Access::UNLISTED)->shouldBe('Unlisted');
    }

    public function it_should_return_unknown_for_invalid_access_id()
    {
        $this::idToString(666)->shouldBe('Unknown');
    }
}