Commit 80522e2f authored by Marcelo Rivera's avatar Marcelo Rivera

(feat): add new MetricsDelegate that pushes the new delete analytics event

1 merge request!380Implement new delete for channel delete to record delete event in elasticsearch
Pipeline #90213920 passed with stages
in 11 minutes and 23 seconds
<?php
/**
* @author: eiennohi.
*/
namespace Minds\Core\Channels\Delegates;
use Minds\Core\Analytics\Metrics\Event;
use Minds\Entities\User;
class MetricsDelegate
{
public function onDelete(User $user)
{
$event = new Event();
$event->setType('action')
->setAction('delete')
->setProduct('platform')
->setUserGuid((string) $user->guid)
->setUserPhoneNumberHash($user->getPhoneNumberHash())
->push();
}
}
......@@ -5,6 +5,7 @@
namespace Minds\Core\Channels;
use Minds\Core\Channels\Delegates\MetricsDelegate;
use Minds\Core\Di\Di;
use Minds\Core\Queue\Interfaces\QueueClient;
use Minds\Entities\User;
......@@ -30,6 +31,9 @@ class Manager
/** @var Delegates\Artifacts\Factory */
protected $artifactsDelegatesFactory;
/** @var MetricsDelegate */
protected $metricsDelegate;
/** @var Delegates\Logout */
protected $logoutDelegate;
......@@ -44,10 +48,12 @@ class Manager
*/
public function __construct(
$artifactsDelegatesFactory = null,
$metricsDelegate = null,
$logoutDelegate = null,
$queueClient = null
) {
$this->artifactsDelegatesFactory = $artifactsDelegatesFactory ?: new Delegates\Artifacts\Factory();
$this->metricsDelegate = $metricsDelegate ?: new MetricsDelegate();
$this->logoutDelegate = $logoutDelegate ?: new Delegates\Logout();
$this->queueClient = $queueClient ?: Di::_()->get('Queue');
}
......@@ -132,6 +138,8 @@ class Manager
if (!$done) {
throw new \Exception("{$delegateClassName} deletion failed for {$userGuid}");
}
$this->metricsDelegate->onDelete($this->user);
} catch (\Exception $e) {
// TODO: Fail?
error_log((string) $e);
......
......@@ -20,6 +20,9 @@ class ManagerSpec extends ObjectBehavior
/** @var Delegates\Artifacts\Factory */
protected $artifactsDelegatesFactory;
/** @var Delegates\MetricsDelegate */
protected $metricsDelegate;
/** @var Delegates\Logout */
protected $logoutDelegate;
......@@ -28,16 +31,19 @@ class ManagerSpec extends ObjectBehavior
public function let(
Delegates\Artifacts\Factory $artifactsDelegatesFactory,
Delegates\MetricsDelegate $metricsDelegate,
Delegates\Logout $logoutDelegate,
QueueClient $queueClient
) {
$this->beConstructedWith(
$artifactsDelegatesFactory,
$metricsDelegate,
$logoutDelegate,
$queueClient
);
$this->artifactsDelegatesFactory = $artifactsDelegatesFactory;
$this->metricsDelegate = $metricsDelegate;
$this->logoutDelegate = $logoutDelegate;
$this->queueClient = $queueClient;
}
......@@ -139,6 +145,9 @@ class ManagerSpec extends ObjectBehavior
->shouldBeCalledTimes(count($deletionDelegates))
->willReturn(true);
$this->metricsDelegate->onDelete($user)
->shouldBeCalled();
$this->logoutDelegate->logout($user)
->shouldBeCalled()
->willReturn(true);
......
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