...
 
Commits (10)
<?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');
}
......@@ -139,6 +145,7 @@ class Manager
}
}
$this->metricsDelegate->onDelete($this->user);
$this->logoutDelegate->logout($this->user);
return true;
......
......@@ -127,38 +127,17 @@ class Resize
$params = $this->getResizeParameters();
// If is animated,
if ($this->image->getNumberImages() > 1) {
foreach ($this->image as $frame) {
// Crop into square.
$frame->cropImage(
$params['selectionwidth'],
$params['selectionheight'],
$params['xoffset'],
$params['yoffset']
);
// Resize canvas to new image
$frame->setImagePage(0, 0, 0, 0);
// If selected with / height differ from selection width/height, then we need to resize
if ($params['selectionwidth'] !== $params['newwidth'] || $params['selectionheight'] !== $params['newheight']) {
$frame->thumbnailImage($params['newwidth'], $params['newheight']);
}
}
} else {
// Crop the image to selection dimensions
$this->image->cropImage(
$params['selectionwidth'],
$params['selectionheight'],
$params['xoffset'],
$params['yoffset']
);
// If selected with / height differ from selection width/height, then we need to resize
if ($params['selectionwidth'] !== $params['newwidth'] || $params['selectionheight'] !== $params['newheight']) {
$this->image->thumbnailImage($params['newwidth'], $params['newheight']);
}
// First crop the image
$this->image->cropImage(
$params['selectionwidth'],
$params['selectionheight'],
$params['xoffset'],
$params['yoffset']
);
// If selected with / height differ from selection width/height, then we need to resize
if ($params['selectionwidth'] !== $params['newwidth'] || $params['selectionheight'] !== $params['newheight']) {
$this->image->thumbnailImage($params['newwidth'], $params['newheight']);
}
$this->output = $this->image;
......
......@@ -54,6 +54,7 @@ class FFMpeg implements ServiceInterface
'ffmpeg.binaries' => '/usr/bin/ffmpeg',
'ffprobe.binaries' => '/usr/bin/ffprobe',
'ffmpeg.threads' => $this->config->get('transcoder')['threads'],
'timeout' => 0,
]);
$this->ffprobe = $ffprobe ?: FFProbeClient::create([
'ffprobe.binaries' => '/usr/bin/ffprobe',
......@@ -253,19 +254,25 @@ class FFMpeg implements ServiceInterface
$pfx = ($rotated ? $opts['width'] : $opts['height']).'.'.$format;
$path = $sourcePath.'-'.$pfx;
try {
echo "\nTranscoding: $path ($this->key)";
echo "\nTranscoding: $path ($this->key)\n";
$formatMap[$format]->on('progress', function ($a, $b, $pct) {
echo "\r$pct% transcoded";
// also emit out to cassandra so frontend can keep track
});
$formatMap[$format]
->setKiloBitRate($opts['bitrate'])
->setAudioChannels(2)
// ->setAudioChannels(2)
->setAudioKiloBitrate($opts['audio_bitrate']);
$video->save($formatMap[$format], $path);
//now upload to s3
$this->uploadTranscodedFile($path, $pfx);
//cleanup tmp file
@unlink($path);
} catch (\Exception $e) {
echo " failed {$e->getMessage()}";
//cleanup tmp file
@unlink($path);
}
}
}
......
......@@ -69,6 +69,11 @@ class Repository
try {
$rows = $this->client->request($query);
if (!$rows) {
return $response;
}
foreach ($rows as $row) {
$user = new User($row['column1']);
$response[] = $user;
......
......@@ -153,7 +153,7 @@ class Image extends File
$w = 1024;
$s = false;
$u = true;
// no break
break;
default:
continue 2;
}
......
......@@ -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);
......