...
 
Commits (2)
......@@ -520,6 +520,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]);
}
......
......@@ -11,7 +11,7 @@ use Minds\Entities\Activity;
*/
class PropagateProperties extends Properties
{
protected $actsOnSubtype = 'blog';
protected $actsOnSubtype = ['blog'];
/**
* Propagate Entity properties to activity
......
......@@ -91,6 +91,7 @@ class PropagateProperties
* 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
{
......@@ -104,6 +105,9 @@ class PropagateProperties
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');
}
}
}
......
......@@ -11,30 +11,30 @@ use Minds\Entities\Activity;
abstract class Properties
{
/**
* @var string
* @var array
*/
protected $actsOnType = 'any';
protected $actsOnType = [];
/**
* @var string
* @var array
*/
protected $actsOnSubtype = 'any';
protected $actsOnSubtype = [];
/**
* @var bool
*/
protected $changed = false;
/**
* @return string
* @return array
*/
public function actsOnType(): string
public function actsOnType(): array
{
return $this->actsOnType;
}
/**
* @return string
* @return array
*/
public function actsOnSubType(): string
public function actsOnSubType(): array
{
return $this->actsOnSubtype;
}
......@@ -42,11 +42,20 @@ abstract class Properties
/**
* @param $entity
* @return bool
* @throws \Exception
*/
public function willActOnEntity($entity): bool
{
if ($this->actsOnType === 'any' || $this->actsOnType === $entity->getType()) {
return $this->actsOnSubtype === 'any' || $this->actsOnSubtype === $entity->getSubtype();
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)) {
return $this->actsOnSubtype === [] || in_array($entity->getSubtype(), $this->actsOnSubtype);
}
return false;
......
......@@ -11,7 +11,7 @@ use Minds\Entities\Activity;
*/
class PropagateProperties extends Properties
{
protected $actsOnType = 'object';
protected $actsOnType = ['object'];
protected $actsOnSubtype = ['image', 'video'];
/**
......@@ -22,8 +22,8 @@ class PropagateProperties extends Properties
*/
public function toActivity($from, Activity $to): Activity
{
if ($this->valueHasChanged($from->title, $to->getMessage())) {
$to->setMessage($from->title);
if ($this->valueHasChanged($from->title, $to->get('title'))) {
$to->set('title', $from->title);
}
$fromData = $from->getActivityParameters();
......@@ -43,6 +43,10 @@ class PropagateProperties extends Properties
*/
public function fromActivity(Activity $from, $to)
{
if ($this->valueHasChanged($from->get('title'), $to->title)) {
$to->title = $from->get('title');
}
return $to;
}
}