Commit 43da7da4 authored by Guy Thouret's avatar Guy Thouret

(feat) Pass the entity to be modified by reference to make interfaces cleaner - #616

1 merge request!303WIP: Propogate Properties when entities get updated
Pipeline #78721930 failed with stages
in 4 minutes and 10 seconds
......@@ -9,7 +9,7 @@ class PropogateBlogProperties extends Properties
{
protected $actsOnSubtype = 'blog';
public function toActivity($from, Activity $to): Activity
public function toActivity($from, Activity &$to): void
{
if ($this->valueHasChanged($from->getTitle(), $to->get('title'))) {
$to->set('title', $from->getTitle());
......@@ -27,12 +27,10 @@ class PropogateBlogProperties extends Properties
if ($this->valueHasChanged($from->getIconUrl(), $to->get('thumbnail_src'))) {
$to->set('thumbnail_src', $from->getIconUrl());
}
return $to;
}
public function fromActivity(Activity $from, $to)
public function fromActivity(Activity $from, &$to): void
{
return $to;
// TODO: Implement fromActivity() method.
}
}
......@@ -9,6 +9,7 @@
namespace Minds\Core\Blogs;
use Minds\Core\Di\Di;
use Minds\Core\Entities\PropogateProperties;
use Minds\Core\Security\Spam;
class Manager
......@@ -31,6 +32,9 @@ class Manager
/** @var Delegates\Search */
protected $search;
/** @var PropogateProperties */
protected $propogateProperties;
/**
* Manager constructor.
* @param null $repository
......@@ -39,6 +43,7 @@ class Manager
* @param null $feeds
* @param null $spam
* @param null $search
* @param PropogateProperties $propogateProperties
* @throws \Exception
*/
public function __construct(
......@@ -47,7 +52,8 @@ class Manager
$slug = null,
$feeds = null,
$spam = null,
$search = null
$search = null,
PropogateProperties $propogateProperties = null
)
{
$this->repository = $repository ?: new Repository();
......@@ -56,6 +62,7 @@ class Manager
$this->feeds = $feeds ?: new Delegates\Feeds();
$this->spam = $spam ?: Di::_()->get('Security\Spam');
$this->search = $search ?: new Delegates\Search();
$this->propogateProperties = $propogateProperties ?? Di::_()->get('PropogateProperties');
}
/**
......@@ -171,6 +178,7 @@ class Manager
}
$this->paywallReview->queue($blog);
$this->propogateProperties->toActivities($blog);
}
return $saved;
......
......@@ -55,7 +55,7 @@ class PropogateProperties
foreach ($this->propogators as $propogator) {
if ($propogator->willActOnEntity($attachment)) {
$attachment = $propogator->fromActivity($activity, $attachment);
$propogator->fromActivity($activity, $attachment);
$this->changed |= $propogator->changed();
}
}
......@@ -69,7 +69,7 @@ class PropogateProperties
{
$activities = $this->getActivitiesForEntity($entity->getGuid());
foreach ($activities as $activity) {
$activity = $this->propogateToActivity($entity, $activity);
$this->propogateToActivity($entity, $activity);
if ($this->changed) {
$this->save->setEntity($activity)->save();
}
......@@ -91,16 +91,14 @@ class PropogateProperties
return $activities;
}
public function propogateToActivity($entity, Activity $activity): Activity
public function propogateToActivity($entity, Activity &$activity): void
{
$this->changed = false;
foreach ($this->propogators as $propogator) {
if ($propogator->willActOnEntity($entity)) {
$activity = $propogator->toActivity($entity, $activity);
$propogator->toActivity($entity, $activity);
$this->changed |= $propogator->changed();
}
}
return $activity;
}
}
......@@ -41,6 +41,7 @@ abstract class Properties
return $this->changed;
}
abstract public function toActivity($from, Activity $to): Activity;
abstract public function fromActivity(Activity $from, $to);
abstract public function toActivity($from, Activity &$to): void;
abstract public function fromActivity(Activity $from, &$to): void;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment