...
 
Commits (23)
......@@ -8,6 +8,9 @@
namespace Minds\Api;
use Minds\Core\Di\Di;
use Minds\Core\Session;
class Exportable implements \JsonSerializable
{
/** @var array */
......@@ -100,6 +103,14 @@ class Exportable implements \JsonSerializable
$exported = $item->export(...$this->exportArgs);
if ($item && Di::_()->get('Features\Manager')->has('permissions')) {
$userGuid = $user ? $user->getGuid() : null;
$permissionsManager = Di::_()->get('Permissions\Manager');
$permissions = $permissionsManager->getList(['user_guid' => Session::getLoggedinUser(),
'entities' => [$item]]);
$exported['permissions'] = $permissions->export();
}
// Shims
// TODO: Maybe allow customization via classes? i.e. JavascriptGuidShim, ExceptionShim, etc
......@@ -126,8 +137,6 @@ class Exportable implements \JsonSerializable
$exported[$exception] = $item->{$exception};
}
//
$output[$key] = $exported;
}
......
......@@ -208,15 +208,25 @@ class Factory
*/
public static function exportable($entities, $exceptions = [], $exportContext = false)
{
$permissionsManager = Di::_()->get('Permissions\Manager');
if (!$entities) {
return [];
}
foreach ($entities as $k => $entity) {
if ($exportContext && method_exists($entity, 'setExportContext')) {
$entity->setExportContext($exportContext);
}
$entities[$k] = $entity->export();
//Calculate new permissions object with the entities
if ($entity && Di::_()->get('Features\Manager')->has('permissions')) {
$userGuid = $user ? $user->getGuid() : null;
$permissions = $permissionsManager->getList(['user_guid' => Session::getLoggedinUser(),
'entities' => [$entity]]);
$entities[$k]['permissions'] = $permissions->export();
}
$entities[$k]['guid'] = (string) $entities[$k]['guid']; //javascript doesn't like long numbers..
if (isset($entities[$k]['ownerObj']['guid'])) {
$entities[$k]['ownerObj']['guid'] = (string) $entity->ownerObj['guid'];
......
......@@ -119,6 +119,7 @@ class authenticate implements Interfaces\Api, Interfaces\ApiIgnorePam
public function delete($pages)
{
/** @var Core\Sessions\Manager $sessions */
$sessions = Di::_()->get('Sessions\Manager');
if (isset($pages[0]) && $pages[0] === 'all') {
......
......@@ -362,7 +362,7 @@ class blog implements Interfaces\Api
}
if ($saved) {
if ($blog->isPublished() && $blog->getAccessId() == Access::PUBLIC) {
if ($blog->isPublished() && in_array($blog->getAccessId(), [Access::PUBLIC, Access::LOGGED_IN], false)) {
if (!$editing || ($editing && !$alreadyPublished) || ($editing && $oldAccessId == Access::UNLISTED)) {
(new CreateActivity())->save($blog);
}
......
......@@ -526,9 +526,6 @@ class newsfeed implements Interfaces\Api
$activity->indexes = ["activity:$activity->owner_guid:edits"]; //don't re-index on edit
(new Core\Translation\Storage())->purge($activity->guid);
$attachmentPaywallDelegate = new Core\Feeds\Activity\Delegates\AttachmentPaywallDelegate();
$attachmentPaywallDelegate->onUpdate($activity);
if (isset($_POST['time_created']) && ($_POST['time_created'] != $activity->getTimeCreated())) {
try {
$timeCreatedDelegate = new Core\Feeds\Activity\Delegates\TimeCreatedDelegate();
......@@ -544,6 +541,8 @@ class newsfeed implements Interfaces\Api
$save->setEntity($activity)
->save();
(new Core\Entities\PropagateProperties())->from($activity);
$activity->setExportContext(true);
return Factory::response(['guid' => $activity->guid, 'activity' => $activity->export(), 'edited' => true]);
}
......
......@@ -67,46 +67,49 @@ class views implements Interfaces\Api
]);
break;
case 'activity':
$activity = new Entities\Activity($pages[1]);
case 'entity':
$entity = Entities\Factory::build($pages[1]);
if (!$activity->guid) {
if (!$entity) {
return Factory::response([
'status' => 'error',
'message' => 'Could not find activity post'
'message' => 'Could not the entity'
]);
}
try {
Core\Analytics\App::_()
if ($entity->type === 'activity') {
try {
Core\Analytics\App::_()
->setMetric('impression')
->setKey($activity->guid)
->setKey($entity->guid)
->increment();
if ($activity->remind_object) {
Core\Analytics\App::_()
if ($entity->remind_object) {
Core\Analytics\App::_()
->setMetric('impression')
->setKey($activity->remind_object['guid'])
->setKey($entity->remind_object['guid'])
->increment();
Core\Analytics\App::_()
Core\Analytics\App::_()
->setMetric('impression')
->setKey($activity->remind_object['owner_guid'])
->setKey($entity->remind_object['owner_guid'])
->increment();
}
}
Core\Analytics\User::_()
Core\Analytics\User::_()
->setMetric('impression')
->setKey($activity->owner_guid)
->setKey($entity->owner_guid)
->increment();
} catch (\Exception $e) {
error_log($e->getMessage());
} catch (\Exception $e) {
error_log($e->getMessage());
}
}
try {
$viewsManager->record(
(new Core\Analytics\Views\View())
->setEntityUrn($activity->getUrn())
->setOwnerGuid((string) $activity->getOwnerGuid())
->setEntityUrn($entity->getUrn())
->setOwnerGuid((string) $entity->getOwnerGuid())
->setClientMeta($_POST['client_meta'] ?? [])
);
} catch (\Exception $e) {
......@@ -114,7 +117,7 @@ class views implements Interfaces\Api
}
Di::_()->get('Referrals\Cookie')
->setEntity($activity)
->setEntity($entity)
->create();
break;
......
......@@ -124,10 +124,14 @@ class feed implements Interfaces\Api
// $next = 0;
// }
$len = count($boosts);
$next = $boosts[$len -1]->getTimestamp();
if ($boosts[$len -1]) {
$next = $boosts[$len -1]->getTimestamp();
}
} elseif ($isBoostFeed) {
$len = count($boosts);
$next = $boosts[$len -1]->getTimestamp();
if ($boosts[$len -1]) {
$next = $boosts[$len -1]->getTimestamp();
}
}
// $ttl = 1800; // 30 minutes
......
......@@ -13,6 +13,12 @@ class emails implements Interfaces\Api
public function get($pages)
{
$user = Core\Session::getLoggedInUser();
if (!$user) {
return Factory::response([
'status' => 'error',
'message' => 'User must be logged in.'
]);
}
$campaigns = [ 'when', 'with', 'global' ];
......
......@@ -78,6 +78,9 @@ class Sums
public function getContractBalance($contract = '', $onlySpend = false)
{
if (!$this->user) {
return 0;
}
$cql = "SELECT SUM(amount) as balance from blockchain_transactions_mainnet WHERE user_guid = ? AND wallet_address = ?";
$values = [
new Varint($this->user->guid),
......
<?php
namespace Minds\Core\Blogs\Delegates;
use Minds\Core\Entities\Propagator\Properties;
use Minds\Entities\Activity;
/**
* Class PropagateProperties
* @package Minds\Core\Blogs\Delegates
*/
class PropagateProperties extends Properties
{
protected $actsOnSubtype = ['blog'];
/**
* Propagate Entity properties to activity
* @param $from
* @param Activity $to
* @return Activity
*/
public function toActivity($from, Activity $to): Activity
{
if ($this->valueHasChanged($from->getTitle(), $to->get('title'))) {
$to->set('title', $from->getTitle());
}
$blurb = strip_tags($from->getBody());
if ($this->valueHasChanged($blurb, $to->get('blurb'))) {
$to->set('blurb', $blurb);
}
if ($this->valueHasChanged($from->getUrl(), $to->getURL())) {
$to->setURL($from->getUrl());
}
if ($this->valueHasChanged($from->getIconUrl(), $to->get('thumbnail_src'))) {
$to->set('thumbnail_src', $from->getIconUrl());
}
return $to;
}
/**
* Propagate activity properties to entity
* @param Activity $from
* @param $to
* @return mixed
*/
public function fromActivity(Activity $from, $to)
{
return $to;
}
}
......@@ -9,6 +9,7 @@
namespace Minds\Core\Blogs;
use Minds\Core\Di\Di;
use Minds\Core\Entities\PropagateProperties;
use Minds\Core\Security\Spam;
class Manager
......@@ -31,6 +32,9 @@ class Manager
/** @var Delegates\Search */
protected $search;
/** @var PropagateProperties */
protected $propagateProperties;
/**
* Manager constructor.
* @param null $repository
......@@ -39,6 +43,7 @@ class Manager
* @param null $feeds
* @param null $spam
* @param null $search
* @param PropagateProperties $propagateProperties
* @throws \Exception
*/
public function __construct(
......@@ -47,7 +52,8 @@ class Manager
$slug = null,
$feeds = null,
$spam = null,
$search = null
$search = null,
PropagateProperties $propagateProperties = null
) {
$this->repository = $repository ?: new Repository();
$this->paywallReview = $paywallReview ?: new Delegates\PaywallReview();
......@@ -55,6 +61,7 @@ class Manager
$this->feeds = $feeds ?: new Delegates\Feeds();
$this->spam = $spam ?: Di::_()->get('Security\Spam');
$this->search = $search ?: new Delegates\Search();
$this->propagateProperties = $propagateProperties ?? Di::_()->get('PropagateProperties');
}
/**
......@@ -170,6 +177,7 @@ class Manager
}
$this->paywallReview->queue($blog);
$this->propagateProperties->from($blog);
}
return $saved;
......
You've received a gift of 2 Minds tokens! You can spend these tokens to earn 2,000 extra views on your content with [Boost](https://www.minds.com/boost?__e_ct_guid=<?= $vars['guid']?>&campaign=<?= $vars['campaign']?>&topic=<?= $vars['topic'] ?>&validator=<?= $vars['validator'] ?>) or to tip your favorite content creators with [Wire](https://www.minds.com/wire?__e_ct_guid=<?= $vars['guid']?>&campaign=<?= $vars['campaign']?>&topic=<?= $vars['topic'] ?>&validator=<?= $vars['validator'] ?>).
Please use the button below to claim your gift (note: you will need to open the link in a web browser, the mobile app is not yet supported):
| |
|:--:|
| [![Claim Gift](https://cdn-assets.minds.com/emails/claim-gift.png){=150x}](https://www.minds.com/wallet/tokens/transactions?__e_ct_guid=<?= $vars['guid']?>&campaign=<?= $vars['campaign']?>&topic=<?= $vars['topic'] ?>&validator=<?= $vars['validator'] ?>) |
| |
......@@ -14,8 +14,6 @@ use Minds\Helpers\MagicAttributes;
/**
* Save Action
* @method Save setEntity($entity)
* @method bool save(...$args)
*/
class Save
{
......
<?php
namespace Minds\Core\Entities\Delegates;
use Minds\Core\Entities\Propagator\Properties;
use Minds\Entities\Activity;
/**
* Class PropagateProperties
* @package Minds\Core\Entities\Delegates
*/
class PropagateProperties extends Properties
{
/**
* Propagate Entity properties to activity
* @param $from
* @param Activity $to
* @return Activity
*/
public function toActivity($from, Activity $to): Activity
{
if ($this->valueHasChanged($from->getNsfw(), $to->getNsfw())) {
$to->setNsfw($from->getNsfw());
}
if ($this->valueHasChanged($from->getNsfwLock(), $to->getNsfwLock())) {
$to->setNsfwLock($from->getNsfwLock());
}
return $to;
}
/**
* Propagate activity properties to entity
* @param Activity $from
* @param $to
* @return mixed
*/
public function fromActivity(Activity $from, $to)
{
if ($this->valueHasChanged($from->getNsfw(), $to->getNsfw())) {
$to->setNsfw($from->getNsfw());
}
if ($this->valueHasChanged($from->getNsfwLock(), $to->getNsfwLock())) {
$to->setNsfwLock($from->getNsfwLock());
}
return $to;
}
}
<?php
namespace Minds\Core\Entities;
use Minds\Core\Data\Call;
use Minds\Core\Di\Di;
use Minds\Core\Entities\Actions\Save;
use Minds\Core\Entities\Propagator\Properties;
use Minds\Core\EntitiesBuilder;
use Minds\Entities\Activity;
use Minds\Core;
/**
* Class PropagateProperties
* @package Minds\Core\Entities
*/
class PropagateProperties
{
/** @var Properties[] */
protected $propagators;
/** @var Call */
private $db;
/** @var Save */
private $save;
/** @var EntitiesBuilder */
private $entitiesBuilder;
/** @var bool */
private $changed = false;
/**
* PropagateProperties constructor.
* @param Call|null $db
* @param Save|null $save
* @param EntitiesBuilder|null $entitiesBuilder
*/
public function __construct(Call $db = null, Save $save = null, EntitiesBuilder $entitiesBuilder = null)
{
$this->db = $db ?? new Call('entities_by_time');
$this->save = $save ?? new Save();
$this->entitiesBuilder = $entitiesBuilder ?? Di::_()->get('EntitiesBuilder');
$this->registerPropagators();
}
/**
* Register PropagateProperties classes
* @throws \Exception
*/
protected function registerPropagators(): void
{
$this->addPropagator(Core\Blogs\Delegates\PropagateProperties::class);
$this->addPropagator(Core\Feeds\Delegates\PropagateProperties::class);
$this->addPropagator(Core\Media\Delegates\PropagateProperties::class);
$this->addPropagator(Core\Entities\Delegates\PropagateProperties::class);
$this->addPropagator(Core\Permissions\Delegates\PropagateProperties::class);
}
public function clearPropogators(): void
{
$this->propagators = [];
}
/**
* Add a propagator to be called in the chain
* @param string $class
* @throws \Exception
*/
protected function addPropagator(string $class): void
{
$obj = new $class();
if (!$obj instanceof Properties) {
throw new \Exception('Propagator class is not a Property Propagator');
}
$this->propagators[] = $obj;
}
/**
* Propagate the properties from the passed entity
* @param $entity
*/
public function from($entity): void
{
if ($entity instanceof Activity) {
$this->fromActivity($entity);
} else {
$this->toActivities($entity);
}
}
/**
* Propagate properties from an Activity to to it's attachment
* @param Activity $activity
* @throws \Minds\Exceptions\StopEventException
* @throws \Exception
*/
protected function fromActivity(Activity $activity): void
{
$this->changed = false;
$attachment = $this->entitiesBuilder->single($activity->get('entity_guid'));
if ($attachment === false) {
return;
}
foreach ($this->propagators as $propagator) {
if ($propagator->willActOnEntity($attachment)) {
$attachment = $propagator->fromActivity($activity, $attachment);
$this->changed |= $propagator->changed();
if (!is_object($attachment)) {
throw new \Exception(get_class($propagator) . ' fromActivity method did not return a modified object');
}
}
}
if ($this->changed) {
$this->save->setEntity($attachment)->save();
}
}
/**
* Propagate properties from an Entity to it's activities
* @param $entity
* @throws \Minds\Exceptions\StopEventException
*/
protected function toActivities($entity): void
{
$activities = $this->getActivitiesForEntity($entity->getGuid());
foreach ($activities as $activity) {
$this->propagateToActivity($entity, $activity);
if ($this->changed) {
$this->save->setEntity($activity)->save();
}
}
}
/**
* Get activities for an entity
* @param string $entityGuid
* @return Activity[]
*/
private function getActivitiesForEntity(string $entityGuid): array
{
$activities = [];
foreach ($this->db->getRow("activity:entitylink:{$entityGuid}") as $activityGuid => $ts) {
$activities[] = $this->entitiesBuilder->single($activityGuid);
}
return $activities;
}
/**
* Propagate properties from and entity to an activity
* @param $entity
* @param Activity $activity
*/
public function propagateToActivity($entity, Activity &$activity): void
{
$this->changed = false;
foreach ($this->propagators as $propagator) {
if ($propagator->willActOnEntity($entity)) {
$activity = $propagator->toActivity($entity, $activity);
$this->changed |= $propagator->changed();
}
}
}
}
<?php
namespace Minds\Core\Entities\Propagator;
use Minds\Entities\Activity;
/**
* Properties class that all PropagateProperties delegates should inherit
* @package Minds\Core\Entities\Propagator
*/
abstract class Properties
{
/**
* @var array
*/
protected $actsOnType = [];
/**
* @var array
*/
protected $actsOnSubtype = [];
/**
* @var bool
*/
protected $changed = false;
/**
* @return array
*/
public function actsOnType(): array
{
return $this->actsOnType;
}
/**
* @return array
*/
public function actsOnSubType(): array
{
return $this->actsOnSubtype;
}
/**
* @param $entity
* @return bool
* @throws \Exception
*/
public function willActOnEntity($entity): bool
{
if (!is_array($this->actsOnType)) {
throw new \Exception('actsOnType must be an array');
}
if (!is_array($this->actsOnSubtype)) {
throw new \Exception('actsOnSubType must be an array');
}
if ($this->actsOnType === [] || in_array($entity->getType(), $this->actsOnType, true)) {
return $this->actsOnSubtype === [] || in_array($entity->getSubtype(), $this->actsOnSubtype, true);
}
return false;
}
/**
* @param $from
* @param $to
* @return bool
*/
protected function valueHasChanged($from, $to): bool
{
$changed = $from !== $to;
$this->changed |= $changed;
return $changed;
}
/**
* @return bool
*/
public function changed(): bool
{
return $this->changed;
}
/**
* @param $from
* @param Activity $to
* @return Activity
*/
abstract public function toActivity($from, Activity $to): Activity;
/**
* @param Activity $from
* @param $to
* @return mixed
*/
abstract public function fromActivity(Activity $from, $to);
}
<?php
/**
* ActivityDelegateInterface
* @author edgebal
*/
namespace Minds\Core\Feeds\Activity\Delegates;
use Minds\Entities\Activity;
interface ActivityDelegateInterface
{
public function onAdd();
public function onUpdate(Activity $activity);
}
<?php
/**
* AttachmentPaywallDelegate
* @author edgebal
*/
namespace Minds\Core\Feeds\Activity\Delegates;
use Minds\Core\Di\Di;
use Minds\Core\Entities\Actions\Save;
use Minds\Core\EntitiesBuilder;
use Minds\Entities\Activity;
class AttachmentPaywallDelegate implements ActivityDelegateInterface
{
/** @var EntitiesBuilder */
protected $entitiesBuilder;
/** @var Save */
protected $save;
/**
* AttachmentPaywallDelegate constructor.
* @param EntitiesBuilder $entitiesBuilder
* @param Save $save
*/
public function __construct(
$entitiesBuilder = null,
$save = null
) {
$this->entitiesBuilder = $entitiesBuilder ?: Di::_()->get('EntitiesBuilder');
$this->save = $save ?: new Save();
}
/**
* @throws \NotImplementedException
*/
public function onAdd()
{
throw new \NotImplementedException();
}
/**
* @param Activity $activity
* @return bool
*/
public function onUpdate(Activity $activity)
{
if ($activity->entity_guid) {
$attachment = $this->entitiesBuilder->single($activity->entity_guid);
if ($attachment->owner_guid == $activity->owner_guid) {
$attachment->access_id = $activity->isPaywall() ? 0 : 2;
if ($attachment->getSubtype() === 'blog') {
$attachment->setHidden($activity->isPaywall());
} else {
$attachment->hidden = $activity->isPaywall();
}
if (method_exists($attachment, 'setFlag')) {
$attachment->setFlag('paywall', (bool) $activity->isPaywall());
}
if (method_exists($attachment, 'setWireThreshold')) {
$attachment->setWireThreshold($activity->getWireThreshold() ?: false);
}
$this->save
->setEntity($attachment)
->save();
}
}
return true;
}
}
<?php
namespace Minds\Core\Feeds\Delegates;
use Minds\Core\Blogs\Blog;
use Minds\Core\Entities\Propagator\Properties;
use Minds\Entities\Activity;
use Minds\Entities\Entity;
/**
* Class PropagateProperties
* @package Minds\Core\Feeds\Delegates
*/
class PropagateProperties extends Properties
{
/**
* Propagate Entity properties to activity
* @param $from
* @param Activity $to
* @return Activity
*/
public function toActivity($from, Activity $to): Activity
{
if ($this->valueHasChanged((int)$from->getModeratorGuid(), (int)$to->getModeratorGuid())) {
$to->setModeratorGuid((int)$from->getModeratorGuid());
}
if ($this->valueHasChanged((int)$from->getTimeModerated(), (int)$to->getTimeModerated())) {
$to->setTimeModerated((int)$from->getTimeModerated());
}
return $to;
}
/**
* Propagate activity properties to entity
* @param Activity $from
* @param Entity|Blog $to
* @return mixed
*/
public function fromActivity(Activity $from, $to)
{
if ($this->valueHasChanged((int)$from->getModeratorGuid(), (int)$to->getModeratorGuid())) {
$to->setModeratorGuid((int)$from->getModeratorGuid());
}
if ($this->valueHasChanged((int)$from->getTimeModerated(), (int)$to->getTimeModerated())) {
$to->setTimeModerated((int)$from->getTimeModerated());
}
$to = $this->propagateAttachmentPaywallProperties($from, $to);
return $to;
}
/**
* @param Activity $from
* @param Entity $to
* @return mixed
*/
private function propagateAttachmentPaywallProperties(Activity $from, $to)
{
if ($to->owner_guid == $from->owner_guid) {
$newAccessId = $from->isPaywall() ? 0 : 2;
if ($this->valueHasChanged($to->access_id, $from->access_id)) {
$to->access_id = $newAccessId;
}
$newHidden = $from->isPayWall();
if ($to->getSubtype() === 'blog') {
/** @var $to Blog */
if ($this->valueHasChanged($to->getHidden(), $newHidden)) {
$to->setHidden($newHidden);
}
} else {
if ($this->valueHasChanged($to->hidden, $newHidden)) {
$to->hidden = $newHidden;
}
}
if (method_exists($to, 'setFlag')) {
if ($this->valueHasChanged($to->getFlag('paywall'), (bool)$from->isPaywall())) {
$to->setFlag('paywall', (bool)$from->isPaywall());
}
}
if (method_exists($to, 'setWireThreshold')) {
if ($this->valueHasChanged($to->getWireThreshold(), $from->getWireThreshold())) {
$to->setWireThreshold($from->getWireThreshold() ?: false);
}
}
}
return $to;
}
}
......@@ -3,12 +3,10 @@
namespace Minds\Core\Feeds\Firehose;
use Minds\Entities\User;
use Minds\Entities\Entity;
use Minds\Core\EntitiesBuilder;
use Minds\Core\Data\Call;
use Minds\Core\Entities\Actions\Save;
use Minds\Core\Di\Di;
use Minds\Core\Feeds\Top\Manager as TopFeedsManager;
use Minds\Core\Entities\PropagateProperties;
class Manager
{
......@@ -16,25 +14,21 @@ class Manager
protected $topFeedsManager;
/** @var ModerationCache */
protected $moderationCache;
/** @var EntitiesBuilder $entitiesBuilder */
protected $entitiesBuilder;
/** @var Call */
protected $db;
/** @var Save */
protected $save;
/** @var PropagateProperties */
protected $propagateProperties;
public function __construct(
TopFeedsManager $topFeedsManager = null,
ModerationCache $moderationCache = null,
EntitiesBuilder $entitiesBuilder = null,
Call $db = null,
Save $save = null
Save $save = null,
PropagateProperties $propagateProperties = null
) {
$this->topFeedsManager = $topFeedsManager ?: Di::_()->get('Feeds\Top\Manager');
$this->moderationCache = $moderationCache ?: new ModerationCache();
$this->entitiesBuilder = $entitiesBuilder ?: Di::_()->get('EntitiesBuilder');
$this->db = $db ?: new Call('entities_by_time');
$this->save = $save ?: new Save(); //Mockable, else instantiate a new one on save.
$this->save = $save ?: new Save();
$this->propagateProperties = $propagateProperties ?? Di::_()->get('PropagateProperties');
}
/**
......@@ -79,7 +73,7 @@ class Manager
* Marks an entity as moderated.
*
* @param $entity the entity to mark as moderated, typeless because images do not inherit entity
* @param User $user the moderator
* @param User $moderator the moderator
* @param int $time
*/
public function save(
......@@ -91,22 +85,8 @@ class Manager
$time = time();
}
//Save the entity
$this->saveEntity($entity, $moderator, $time);
if (method_exists($entity, 'getType')
&& $entity->getType() == 'activity'
&& $entity->get('entity_guid')
) {
$attachment = $this->entitiesBuilder->single($entity->get('entity_guid'));
$this->saveEntity($attachment, $moderator, $time);
}
//Moderate parents
foreach ($this->db->getRow('activity:entitylink:'.$entity->getGUID()) as $parentGuid => $ts) {
$activity = $this->entitiesBuilder->single($parentGuid);
$this->saveEntity($activity, $moderator, $time);
}
$this->propagateProperties->from($entity);
}
private function saveEntity(
......
<?php
namespace Minds\Core\Media\Delegates;
use Minds\Core\Entities\Propagator\Properties;
use Minds\Entities\Activity;
/**
* Class PropagateProperties
* @package Minds\Core\Media\Delegates
*/
class PropagateProperties extends Properties
{
protected $actsOnType = ['object'];
protected $actsOnSubtype = ['image', 'video'];
/**
* Propagate Entity properties to activity
* @param $from
* @param Activity $to
* @return Activity
*/
public function toActivity($from, Activity $to): Activity
{
if ($this->valueHasChanged($from->title, $to->getMessage())) {
$to->setMessage($from->title);
}
$fromData = $from->getActivityParameters();
$toData = $to->getCustom();
if ((!isset($toData[1])) || (isset($toData[1]) && $this->valueHasChanged($fromData[1], $toData[1]))) {
$to->setCustom($fromData[0], $fromData[1]);
}
return $to;
}
/**
* Propagate activity properties to entity
* @param Activity $from
* @param $to
* @return mixed
*/
public function fromActivity(Activity $from, $to)
{
if ($this->valueHasChanged($from->getMessage(), $to->title)) {
$to->title = $from->getMessage();
}
return $to;
}
}
<?php
/**
* @author: eiennohi.
*/
namespace Minds\Core\Media\Delegates;
use Minds\Core\Data\Call;
use Minds\Entities\Image;
use Minds\Entities\Video;
class UpdateActivities
{
/** @var Call */
private $indexDb;
private $entityDb;
public function __construct($indexDb = null, $entityDb = null)
{
$this->indexDb = $indexDb ?: new Call('entities_by_time');
$this->entityDb = $entityDb ?: new Call('entities');
}
/**
* @param Image|Video $entity
*/
public function updateActivities($entity)
{
foreach ($this->indexDb->getRow("activity:entitylink:{$entity->guid}") as $guid => $ts) {
$this->entityDb->insert($guid, ['message' => $entity->title]);
$parameters = $entity->getActivityParameters();
$this->entityDb->insert($guid, ['custom_type' => $parameters[0]]);
$this->entityDb->insert($guid, ['custom_data' => json_encode($parameters[1])]);
}
}
}
......@@ -5,17 +5,15 @@ namespace Minds\Core\Media;
use Minds\Core;
use Minds\Entities;
use Minds\Helpers;
use Minds\Core\Media;
class Feeds
{
private $updateActivitiesDelegate;
protected $entity;
protected $propagateProperties;
public function __construct($updateActivitiesDelegate = null)
public function __construct(Core\Entities\PropagateProperties $propagateProperties = null)
{
$this->updateActivitiesDelegate = $updateActivitiesDelegate ?: new Delegates\UpdateActivities();
$this->propagateProperties = $propagateProperties ?? Core\Di\Di::_()->get('PropagateProperties');
}
public function setEntity($entity)
......@@ -25,7 +23,7 @@ class Feeds
return $this;
}
public function createActivity()
public function createActivity(): Entities\Activity
{
if (!$this->entity) {
throw new \Exception('Entity not set');
......@@ -54,7 +52,7 @@ class Feeds
throw new \Exception('Entity not set');
}
$this->updateActivitiesDelegate->updateActivities($this->entity);
$this->propagateProperties->from($this->entity);
}
public function dispatch(array $targets = [])
......
......@@ -80,7 +80,7 @@ class TranscodingStatus
public function isTranscodingComplete()
{
$transcodes = $this->getTranscodes();
return (count($transcodes) === $this->getExpectedTranscodeCount());
return (count($transcodes) >= $this->getExpectedTranscodeCount());
}
/**
......@@ -90,7 +90,7 @@ class TranscodingStatus
{
return array_reduce($this->presets, function ($count, $preset) {
return $count + count($preset['formats']);
}, 0);
}, 0) / 2; // 50% is ok
}
/**
......
......@@ -78,21 +78,22 @@ class Manager
// Required for JP only
if ($account->getGender()) {
$data['legal_entity']['gender'] = $account->getGender();
$data['individual']['gender'] = $account->getGender();
}
if ($account->getPhoneNumber()) {
$data['legal_entity']['phone_number'] = $account->getPhoneNumber();
$data['individual']['phone'] = $account->getPhoneNumber();
}
// US 1099 requires SSN
if ($account->getSSN()) {
$data['legal_entity']['ssn_last_4'] = $account->getSSN();
$data['individual']['ssn_last_4'] = $account->getSSN();
$data['requested_capabilities'] = ['card_payments', 'transfers'];
}
if ($account->getPersonalIdNumber()) {
$data['legal_entity']['personal_id_number'] = $account->getPersonalIdNumber();
$data['individual']['id_number'] = $account->getPersonalIdNumber();
}
$result = $this->accountInstance->create($data);
......
<?php
namespace Minds\Core\Permissions\Delegates;
use Minds\Core\Entities\Propagator\Properties;
use Minds\Entities\Activity;
/**
* Class PropagateProperties
* @package Minds\Core\Permissions\Delegates
*/
class PropagateProperties extends Properties
{
/**
* Propagate Entity properties to activity
* @param $from
* @param Activity $to
* @return Activity
*/
public function toActivity($from, Activity $to): Activity
{
if ($this->valueHasChanged($from->getAllowComments(), $to->getAllowComments())) {
$to->setAllowComments($from->getAllowComments());
}
return $to;
}
/**
* Propagate activity properties to entity
* @param Activity $from
* @param $to
* @return mixed
*/
public function fromActivity(Activity $from, $to)
{
if ($this->valueHasChanged($from->getAllowComments(), $to->getAllowComments())) {
$to->setAllowComments($from->getAllowComments());
}
return $to;
}
}
......@@ -118,10 +118,10 @@ class Repository
$contributions[] = $contribution;
}
$pagingStateToken = $rows ? $rows->pagingStateToken() : null;
return [
'contributions' => $contributions,
'token' => $rows->pagingStateToken()
'token' => $pagingStateToken
];
}
......
......@@ -2,6 +2,7 @@
/**
* Minds Session Manager
*/
namespace Minds\Core\Sessions;
use Minds\Common\Cookie;
......@@ -184,13 +185,13 @@ class Manager
$expires = time() + (60 * 60 * 24 * 30); // 30 days
$token = $this->jwtBuilder
//->issuedBy($this->config->get('site_url'))
//->canOnlyBeUsedBy($this->config->get('site_url'))
->setId($id, true)
->setExpiration($expires)
->set('user_guid', (string) $this->user->getGuid())
->sign(new Sha512, $this->config->get('sessions')['private_key'])
->getToken();
//->issuedBy($this->config->get('site_url'))
//->canOnlyBeUsedBy($this->config->get('site_url'))
->setId($id, true)
->setExpiration($expires)
->set('user_guid', (string) $this->user->getGuid())
->sign(new Sha512, $this->config->get('sessions')['private_key'])
->getToken();
$this->session = new Session();
$this->session
......@@ -198,7 +199,7 @@ class Manager
->setToken($token)
->setUserGuid($this->user->getGuid())
->setExpires($expires);
return $this;
}
......@@ -234,8 +235,10 @@ class Manager
*/
public function destroy($all = false)
{
$this->repository->delete($this->session, $all);
if ($this->session) {
$this->repository->delete($this->session, $all);
}
$this->cookie
->setName('minds_sess')
->setValue('')
......
......@@ -343,6 +343,15 @@ class Activity extends Entity
return $this;
}
/**
* Set the message
* @return string
*/
public function getMessage(): string
{
return $this->message;
}
/**
* Sets the title
* @param string $title
......@@ -440,6 +449,18 @@ class Activity extends Entity
return $this;
}
/**
* Get the custom data
* @return array
*/
public function getCustom(): array
{
return [
$this->custom_type,
$this->custom_data
];
}
/**
* Set the to_guid
* @param int $guid
......
......@@ -23,5 +23,8 @@ class EntitiesProvider extends Provider
$this->di->bind('Entities\Factory', function ($di) {
return new EntitiesFactory();
}, ['useFactory' => true]);
$this->di->bind('PropagateProperties', function ($di) {
return new Entities\PropagateProperties();
}, ['useFactory' => true]);
}
}
......@@ -8,14 +8,6 @@ use Minds\Interfaces\Flaggable;
* File Entity
* @todo Do not inherit from ElggFile
* @package Minds\Entities\File
* @method array getExportableValues()
* @method mixed|null getFlag(string $flag)
* @method File setFlag(string $flag, mixed $value)
* @method void save(bool $index)
* @method array getWireTotals()
* @method mixed getWireThreshold()
* @method File setWireThreshold(int $wire_threshold)
* @method int getModeratorGUID()
*/
class File extends \ElggFile implements Flaggable
{
......
......@@ -422,6 +422,18 @@ class Group extends NormalizedEntity
$this->conversationDisabled = $value ? 1 : 0;
return $this;
}
/**
* Return the original `owner_guid` for the group.
* @return string guid
*/
public function getOwnerGuid()
{
$guids = $this->getOwnerGuids();
return $guids
? guids[0]
: $this->getOwnerObj()->guid;
}
/**
* Gets `owner_guids`
......
......@@ -75,8 +75,8 @@ class EmailRewards
$validator = $_GET['validator'];
//$key = '.md';
//return;
if ($validator == sha1($campaign . 'gift-25-06-19.mdl' . $topic . $user->guid . Config::_()->get('emails_secret'))) {
$tokens = 5 * (10 ** 18);
if ($validator == sha1($campaign . 'gift-30-09-19.mdl' . $topic . $user->guid . Config::_()->get('emails_secret'))) {
$tokens = 2 * (10 ** 18);
$campaign = $validator; //hack
} else {
return;
......
<?php
namespace Spec\Minds\Core\Blogs\Delegates;
use Minds\Core\Blogs\Blog;
use Minds\Entities\Activity;
use Minds\Entities\Entity;
use PhpSpec\ObjectBehavior;
class PropagatePropertiesSpec extends ObjectBehavior
{
/** @var Blog */
protected $blog;
/** @var Activity */
protected $activity;
public function let(
Blog $blog,
Activity $activity
) {
$this->blog = $blog;
$this->activity = $activity;
}
public function it_is_initializable()
{
$this->shouldHaveType('Minds\Core\Blogs\Delegates\PropagateProperties');
}
public function it_should_propagate_changes_to_activity()
{
$this->blog->getTitle()->shouldBeCalled()->willReturn('New Title');
$this->activity->get('title')->shouldBeCalled()->willReturn('Old Title');
$this->activity->set('title', 'New Title')->shouldBeCalled();
$this->blog->getBody()->shouldBeCalled()->willReturn('body');
$this->activity->get('blurb')->shouldBeCalled()->willReturn('body');
$this->blog->getUrl()->shouldBeCalled()->willReturn('some url');
$this->activity->getURL()->shouldBeCalled()->willReturn('some url');
$this->blog->getIconUrl()->shouldBeCalled()->willReturn('some icon url');
$this->activity->get('thumbnail_src')->shouldBeCalled()->willReturn('some other url');
$this->activity->set('thumbnail_src', 'some icon url')->shouldBeCalled();
$this->toActivity($this->blog, $this->activity);
}
}
......@@ -5,6 +5,7 @@ namespace Spec\Minds\Core\Blogs;
use Minds\Core\Blogs\Blog;
use Minds\Core\Blogs\Delegates;
use Minds\Core\Blogs\Repository;
use Minds\Core\Entities\PropagateProperties;
use Minds\Core\Security\Spam;
use PhpSpec\ObjectBehavior;
......@@ -30,13 +31,16 @@ class ManagerSpec extends ObjectBehavior
/** @var Delegates\Search */
protected $search;
protected $propagateProperties;
public function let(
Repository $repository,
Delegates\PaywallReview $paywallReview,
Delegates\Slug $slug,
Delegates\Feeds $feeds,
Spam $spam,
Delegates\Search $search
Delegates\Search $search,
PropagateProperties $propagateProperties
) {
$this->beConstructedWith(
$repository,
......@@ -44,7 +48,8 @@ class ManagerSpec extends ObjectBehavior
$slug,
$feeds,
$spam,
$search
$search,
$propagateProperties
);
$this->repository = $repository;
......@@ -53,6 +58,7 @@ class ManagerSpec extends ObjectBehavior
$this->feeds = $feeds;
$this->spam = $spam;
$this->search = $search;
$this->propagateProperties = $propagateProperties;
}
public function it_is_initializable()
......@@ -244,6 +250,7 @@ class ManagerSpec extends ObjectBehavior
->shouldBeCalled()
->willReturn(true);
$this->propagateProperties->from($blog)->shouldBeCalled();
$this
->update($blog)
->shouldReturn(true);
......
<?php
namespace Spec\Minds\Core\Entities\Delegates;
use Minds\Core\Blogs\Blog;
use Minds\Entities\Activity;
use PhpSpec\ObjectBehavior;
class PropagatePropertiesSpec extends ObjectBehavior
{
/** @var Blog */
protected $blog;
/** @var Activity */
protected $activity;
public function let(
Blog $blog,
Activity $activity
) {
$this->blog = $blog;
$this->activity = $activity;
}
public function it_is_initializable()
{
$this->shouldHaveType('Minds\Core\Entities\Delegates\PropagateProperties');
}
public function it_should_propagate_changes_to_activity()
{
$this->blog->getNsfw()->shouldBeCalled()->willReturn([1]);
$this->activity->getNsfw()->shouldBeCalled()->willReturn([]);
$this->activity->setNsfw([1])->shouldBeCalled();
$this->blog->getNsfwLock()->shouldBeCalled()->willReturn([1]);
$this->activity->getNsfwLock()->shouldBeCalled()->willReturn([]);
$this->activity->setNsfwLock([1])->shouldBeCalled();
$this->toActivity($this->blog, $this->activity);
}
public function it_should_propogate_properties_from_activity()
{
$this->activity->getNsfw()->shouldBeCalled()->willReturn([1]);
$this->blog->getNsfw()->shouldBeCalled()->willReturn([]);
$this->blog->setNsfw([1])->shouldBeCalled();
$this->activity->getNsfwLock()->shouldBeCalled()->willReturn([1]);
$this->blog->getNsfwLock()->shouldBeCalled()->willReturn([]);
$this->blog->setNsfwLock([1])->shouldBeCalled();
$this->fromActivity($this->activity, $this->blog);
}
}
<?php
namespace Spec\Minds\Core\Entities;
use Minds\Core\Data\Call;
use Minds\Core\Entities\Actions\Save;
use Minds\Core\EntitiesBuilder;
use Minds\Entities\Activity;
use Minds\Entities\Entity;
use PhpSpec\ObjectBehavior;
class PropagatePropertiesSpec extends ObjectBehavior
{
protected $db;
protected $save;
protected $entitiesBuilder;
protected $propagator;
protected $activity;
protected $entity;
public function let(
Call $db,
Save $save,
EntitiesBuilder $entitiesBuilder,
Activity $activity,
Entity $entity
) {
$this->beConstructedWith($db, $save, $entitiesBuilder);
$this->db = $db;
$this->save = $save;
$this->entitiesBuilder = $entitiesBuilder;
$this->activity = $activity;
$this->entity = $entity;
$this->clearPropogators();
}
public function it_is_initializable()
{
$this->shouldHaveType('Minds\Core\Entities\PropagateProperties');
}
public function it_should_call_from_activity()
{
$this->activity->get('entity_guid')->shouldBeCalled()->willReturn(1001);
$this->entitiesBuilder->single(1001)->shouldBeCalled()->willReturn($this->entity);
$this->from($this->activity);
}
public function it_should_call_to_activities()
{
$this->entity->getGUID()->shouldBeCalled()->willReturn(1002);
$this->db->getRow("activity:entitylink:1002")->shouldBeCalled()->willReturn([1001 => 12345]);
$this->entitiesBuilder->single(1001)->shouldBeCalled()->willReturn($this->activity);
$this->from($this->entity);
}
}
<?php
namespace Spec\Minds\Core\Feeds\Delegates;
use Minds\Entities\Activity;
use Minds\Entities\Entity;
use PhpSpec\ObjectBehavior;
class PropagatePropertiesSpec extends ObjectBehavior
{
/** @var Entity */
protected $entity;
/** @var Activity */
protected $activity;
public function let(
Entity $entity,
Activity $activity
) {
$this->entity = $entity;
$this->activity = $activity;
}
public function it_is_initializable()
{
$this->shouldHaveType('Minds\Core\Feeds\Delegates\PropagateProperties');
}
public function it_should_propagate_changes_to_activity()
{
$this->entity->getModeratorGuid()->shouldBeCalled()->willReturn('12345');
$this->activity->getModeratorGuid()->shouldBeCalled()->willReturn('6789');
$this->activity->setModeratorGuid('12345')->shouldBeCalled();
$this->entity->getTimeModerated()->shouldBeCalled()->willReturn(12345);
$this->activity->getTimeModerated()->shouldBeCalled()->willReturn(6789);
$this->activity->setTimeModerated(12345)->shouldBeCalled();
$this->toActivity($this->entity, $this->activity);
}
public function it_should_propogate_properties_from_activity()
{
$this->activity->getModeratorGuid()->shouldBeCalled()->willReturn('12345');
$this->entity->getModeratorGuid()->shouldBeCalled()->willReturn('6789');
$this->entity->setModeratorGuid('12345')->shouldBeCalled();
$this->activity->getTimeModerated()->shouldBeCalled()->willReturn(12345);
$this->entity->getTimeModerated()->shouldBeCalled()->willReturn(6789);
$this->entity->setTimeModerated(12345)->shouldBeCalled();
$this->entity->get('owner_guid')->shouldBeCalled()->willReturn(123);
$this->activity->get('owner_guid')->shouldBeCalled()->willReturn(123);
$this->activity->isPayWall()->shouldBeCalled()->willReturn(true);
$this->activity->get('access_id')->shouldBeCalled()->willReturn(0);
$this->entity->get('access_id')->shouldBeCalled()->willReturn(2);
$this->entity->set('access_id', 0)->shouldBeCalled();
$this->entity->getSubtype()->shouldBeCalled()->willReturn('image');
$this->entity->get('hidden')->shouldBeCalled()->willReturn(false);
$this->entity->set('hidden', true)->shouldBeCalled();
$this->fromActivity($this->activity, $this->entity);
}
}
......@@ -2,6 +2,7 @@
namespace Spec\Minds\Core\Feeds\Firehose;
use Minds\Core\Entities\PropagateProperties;
use PhpSpec\ObjectBehavior;
use Minds\Entities\User;
use Minds\Core\Feeds\Firehose\Manager;
......@@ -25,12 +26,10 @@ class ManagerSpec extends ObjectBehavior
protected $topFeedsManager;
/** @var ModerationCache */
protected $moderationCache;
/** @var EntitiesBuilder */
protected $entitiesBuilder;
/** @var Call */
protected $db;
/** @var Save */
protected $save;
/** @var PropagateProperties */
protected $propagateProperties;
protected $guids = [
'968599624820461570', '966142563226488850', '966145446911152135',
......@@ -43,25 +42,22 @@ class ManagerSpec extends ObjectBehavior
User $user,
TopFeedsManager $topFeedsManager,
ModerationCache $moderationCache,
EntitiesBuilder $entitiesBuilder,
Call $db,
Save $save
Save $save,
PropagateProperties $propagateProperties
) {
$this->user = $user;
$this->topFeedsManager = $topFeedsManager;
$this->moderationCache = $moderationCache;
$this->entitiesBuilder = $entitiesBuilder;
$this->db = $db;
$this->save = $save;
$this->propagateProperties = $propagateProperties;
$this->user->getGUID()->willReturn(123);
$this->beConstructedWith(
$this->topFeedsManager,
$this->moderationCache,
$this->entitiesBuilder,
$this->db,
$this->save
$this->save,
$this->propagateProperties
);
}
......@@ -77,10 +73,10 @@ class ManagerSpec extends ObjectBehavior
$response = new Response($activities);
$this->topFeedsManager->getList([
'moderation_user' => $this->user,
'exclude_moderated' => true,
'moderation_reservations' => null,
])
'moderation_user' => $this->user,
'exclude_moderated' => true,
'moderation_reservations' => null,
])
->shouldBeCalled()
->willReturn($response);
......@@ -112,89 +108,22 @@ class ManagerSpec extends ObjectBehavior
'exclude_moderated' => true,
'moderation_reservations' => null,
])
->shouldBeCalled()
->willReturn($response);
->shouldBeCalled()
->willReturn($response);
$this->getList()->shouldBeLike($response->map(function ($entity) {
return $entity->getEntity();
}));
}
public function it_should_save_moderated_activites(Entity $activity)
{
$time = time();
$this->db->getRow('activity:entitylink:1')->shouldBeCalled()->willReturn([]);
$activity->getType()->shouldBeCalled()->willReturn('activity');
$activity->get('entity_guid')->shouldBeCalled()->willReturn(false);
$activity->getGUID()->shouldBeCalled()->willReturn(1);
$activity->setModeratorGuid('123')->shouldBeCalled();
$activity->setTimeModerated($time)->shouldBeCalled();
$this->save->setEntity($activity)->shouldBeCalled()->willReturn($this->save);
$this->save->save()->shouldBeCalled();
$this->save($activity, $this->user, $time);
}
public function it_should_save_reported_activites(Entity $activity)
public function it_should_save_and_propogate(Entity $activity)
{
$time = time();
$this->db->getRow('activity:entitylink:1')->shouldBeCalled()->willReturn([]);
$activity->getType()->shouldBeCalled()->willReturn('activity');
$activity->get('entity_guid')->shouldBeCalled()->willReturn(false);
$activity->getGUID()->shouldBeCalled()->willReturn(1);
$activity->setTimeModerated($time)->shouldBeCalled();
$activity->setModeratorGuid('123')->shouldBeCalled();
$this->save->setEntity($activity)->shouldBeCalled()->willReturn($this->save);
$this->save->save()->shouldBeCalled();
$this->save($activity, $this->user, $time);
}
public function it_should_save_an_attachment(Entity $activity, Image $image)
{
$time = time();
$image->setModeratorGuid(123)->shouldBeCalled();
$image->setTimeModerated($time)->shouldBeCalled();
$this->db->getRow('activity:entitylink:1')->shouldBeCalled()->willReturn([]);
$this->entitiesBuilder->single(1)->shouldBeCalled()->willReturn($image);
$activity->getType()->shouldBeCalled()->willReturn('activity');
$activity->get('entity_guid')->shouldBeCalled()->willReturn(1);
$activity->getGUID()->shouldBeCalled()->willReturn(1);
$activity->setTimeModerated($time)->shouldBeCalled();
$activity->setModeratorGuid(123)->shouldBeCalled();
$this->save->setEntity($activity)->shouldBeCalled()->willReturn($this->save);
$this->save->setEntity($image)->shouldBeCalled()->willReturn($this->save);
$this->save->save()->shouldBeCalled();
$this->save($activity, $this->user, $time);
}
public function it_should_save_a_blog(Blog $blog)
{
$time = time();
$this->db->getRow('activity:entitylink:1')->shouldBeCalled()->willReturn([]);
$blog->getType()->shouldBeCalled()->willReturn('object');
$blog->getGuid()->shouldBeCalled()->willReturn(1);
$blog->setTimeModerated($time)->shouldBeCalled();
$blog->setModeratorGuid('123')->shouldBeCalled();
$this->save->save()->shouldBeCalled();
$this->save->setEntity($blog)->shouldBeCalled()->willReturn($this->save);
$this->save($blog, $this->user, $time);
}
public function it_should_save_a_linked_entity(Entity $activity, Entity $parent)
{
$time = time();
$parent->setTimeModerated($time)->shouldBeCalled();
$parent->setModeratorGuid('123')->shouldBeCalled();
$this->db->getRow('activity:entitylink:1')->shouldBeCalled()
->willReturn([2 => $parent]);
$this->entitiesBuilder->single(2)->shouldBeCalled()->willReturn($parent);
$activity->getType()->shouldBeCalled()->willReturn('activity');
$activity->get('entity_guid')->shouldBeCalled()->willReturn(false);
$activity->getGUID()->shouldBeCalled()->willReturn(1);
$activity->setTimeModerated($time)->shouldBeCalled();
$activity->setModeratorGuid('123')->shouldBeCalled();
$this->save->setEntity($activity)->shouldBeCalled()->willReturn($this->save);
$this->save->setEntity($parent)->shouldBeCalled()->willReturn($this->save);
$this->save->save()->shouldBeCalled();
$this->propagateProperties->from($activity)->shouldBeCalled();
$this->save($activity, $this->user, $time);
}
......
<?php
namespace Spec\Minds\Core\Media\Delegates;
use Minds\Entities\Activity;
use Minds\Entities\Image;
use PhpSpec\ObjectBehavior;
class PropagatePropertiesSpec extends ObjectBehavior
{
/** @var Image */
protected $entity;
/** @var Activity */
protected $activity;
public function let(
Image $entity,
Activity $activity
) {
$this->entity = $entity;
$this->activity = $activity;
}
public function it_is_initializable()
{
$this->shouldHaveType('Minds\Core\Media\Delegates\PropagateProperties');
}
public function it_should_propagate_changes_to_activity()
{
$this->entity->get('title')->shouldBeCalled()->willReturn('new title');
$this->activity->getMessage()->shouldBeCalled()->willReturn('old title');
$this->activity->setMessage('new title')->shouldBeCalled();
$activityParameters = [
'batch',
[
'key1' => 'value1',
'key2' => 'value2'
]
];
$this->entity->getActivityParameters()->shouldBeCalled()->willReturn($activityParameters);
$this->activity->getCustom()->shouldBeCalled()->willReturn([]);
$this->activity->setCustom($activityParameters[0], $activityParameters[1])->shouldBeCalled();
$this->toActivity($this->entity, $this->activity);
}
public function it_should_propogate_properties_from_activity()
{
$this->activity->getMessage()->shouldBeCalled()->willReturn('new title');
$this->entity->get('title')->shouldbeCalled()->willReturn('old title');
$this->entity->set('title', 'new title')->shouldBeCalled();
$this->fromActivity($this->activity, $this->entity);
}
}
......@@ -26,6 +26,10 @@ class TranscodingStatusSpec extends ObjectBehavior
[
'height' => 1080,
'formats' => ['mp4', 'webm']
],
[
'height' => 360,
'formats' => ['mp4', 'webm']
]
]
]);
......@@ -52,12 +56,27 @@ class TranscodingStatusSpec extends ObjectBehavior
$result = new Result(['Contents' => [
['Key' => '/test/123/1080.mp4'],
['Key' => '/test/123/1080.webm'],
['Key' => '/test/123/360.mp4'],
['Key' => '/test/123/360.webm'],
['Key' => '/test/123/thumbnail-00000.png']
]]);
$this->beConstructedWith($this->video, $result, $this->config);
$this->hasSource()->shouldReturn(false);
$this->getTranscodes()->shouldReturn(['/test/123/1080.mp4', '/test/123/1080.webm']);
$this->getTranscodes()->shouldReturn(['/test/123/1080.mp4', '/test/123/1080.webm', '/test/123/360.mp4', '/test/123/360.webm']);
$this->getThumbnails()->shouldContain('/test/123/thumbnail-00000.png');
$this->isTranscodingComplete()->shouldReturn(true);
}
public function it_should_say_still_transcoding()
{
$result = new Result(['Contents' => [
['Key' => '/test/123/360.mp4'],
['Key' => '/test/123/thumbnail-00000.png']
]]);
$this->beConstructedWith($this->video, $result, $this->config);
$this->hasSource()->shouldReturn(false);
$this->getTranscodes()->shouldReturn(['/test/123/360.mp4']);
$this->getThumbnails()->shouldContain('/test/123/thumbnail-00000.png');
$this->isTranscodingComplete()->shouldReturn(false);
}
}
<?php
namespace Spec\Minds\Core\Permissions\Delegates;
use Minds\Entities\Activity;
use Minds\Entities\Entity;
use PhpSpec\ObjectBehavior;
class PropagatePropertiesSpec extends ObjectBehavior
{
/** @var Entity */
protected $entity;
/** @var Activity */
protected $activity;
public function let(
Entity $entity,
Activity $activity
) {
$this->entity = $entity;
$this->activity = $activity;
}
public function it_is_initializable()
{
$this->shouldHaveType('Minds\Core\Permissions\Delegates\PropagateProperties');
}
public function it_should_propagate_changes_to_activity()
{
$this->entity->getAllowComments()->shouldBeCalled()->willReturn(true);
$this->activity->getAllowComments()->shouldBeCalled()->willReturn(false);
$this->activity->setAllowComments(true)->shouldBeCalled();
$this->toActivity($this->entity, $this->activity);
}
public function it_should_propogate_properties_from_activity()
{
$this->activity->getAllowComments()->shouldBeCalled()->willReturn(true);
$this->entity->getAllowComments()->shouldBeCalled()->willReturn(false);
$this->entity->setAllowComments(true)->shouldBeCalled();
$this->fromActivity($this->activity, $this->entity);
}
}