Skip to content

Commit

Permalink
Temporarily disabled push mode in export context. in response to #150
Browse files Browse the repository at this point in the history
  • Loading branch information
arabcoders committed Jun 8, 2022
1 parent 6ad04f4 commit 3e2795f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
25 changes: 16 additions & 9 deletions src/Commands/State/ExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ protected function process(InputInterface $input, OutputInterface $output): int

unset($backend);

if (true === $this->isPushable($backends, $input)) {
if (true === $this->isPushable($backends, $input, ['push' => false])) {
$this->logger->info('Using push mode.');
$this->push($backends, $input);
$this->push($backends);
} else {
$this->logger->info('Using export mode.');
$this->export($backends, $input);
Expand Down Expand Up @@ -410,23 +410,30 @@ protected function export(array $backends, InputInterface $input): mixed
*
* @param array $backends
* @param InputInterface $input
* @param array $opts
*
* @return bool
*/
protected function isPushable(array $backends, InputInterface $input): bool
protected function isPushable(array $backends, InputInterface $input, array $opts = []): bool
{
// -- disable push mode in response to #150
if (false === (bool)ag($opts, 'push')) {
$this->logger->notice('Push mode is disabled for export in response to bug report #150.');
return false;
}

if (true === $input->getOption('force-full')) {
$this->logger->info('Not possible to use push mode when [-f, --force-full] flag is used.');
$this->logger->notice('Not possible to use push mode when [-f, --force-full] flag is used.');
return false;
}

if (true === $input->getOption('force-push-mode')) {
$this->logger->info('Force Push mode flag is used.');
$this->logger->notice('Force Push mode flag is used.');
return true;
}

if (true === $input->getOption('force-export-mode')) {
$this->logger->info('Force Export mode flag is used.');
$this->logger->notice('Force Export mode flag is used.');
return false;
}

Expand All @@ -441,14 +448,14 @@ protected function isPushable(array $backends, InputInterface $input): bool
$backend,
'options.' . Options::IMPORT_METADATA_ONLY
)) {
$this->logger->info(
$this->logger->notice(
sprintf('%s: Import are disabled from this backend. Falling back to export mode.', $name)
);
return false;
}

if (null === ($after = ag($backend, 'export.lastSync', null))) {
$this->logger->info(
$this->logger->notice(
sprintf('%s: This backend has not been synced before. falling back to export mode.', $name)
);
return false;
Expand All @@ -457,7 +464,7 @@ protected function isPushable(array $backends, InputInterface $input): bool
$count = $this->storage->getCount(makeDate($after));

if ($count > $threshold) {
$this->logger->info(
$this->logger->notice(
sprintf('%s: Media changes exceed push threshold. falling back to export mode.', $name),
[
'threshold' => $threshold,
Expand Down
12 changes: 8 additions & 4 deletions tests/Mappers/Import/DirectMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use App\Libs\Data;
use App\Libs\Entity\StateEntity;
use App\Libs\Entity\StateInterface as iFace;
use App\Libs\Extends\ConsoleHandler;
use App\Libs\Guid;
use App\Libs\Mappers\Import\DirectMapper;
use App\Libs\Storage\PDO\PDOAdapter;
use App\Libs\Storage\StorageInterface;
use Monolog\Handler\TestHandler;
use Monolog\Logger;
use PDO;
use PHPUnit\Framework\TestCase;
Expand All @@ -23,8 +23,9 @@ class DirectMapperTest extends TestCase
private array $testMovie = [];
private array $testEpisode = [];

private DirectMapper|null $mapper = null;
private StorageInterface|null $storage = null;
protected DirectMapper|null $mapper = null;
protected StorageInterface|null $storage = null;
protected TestHandler|null $handler = null;

public function setUp(): void
{
Expand All @@ -34,12 +35,15 @@ public function setUp(): void
$this->testMovie = require __DIR__ . '/../../Fixtures/MovieEntity.php';
$this->testEpisode = require __DIR__ . '/../../Fixtures/EpisodeEntity.php';

$this->handler = new TestHandler();
$logger = new Logger('logger');
$logger->pushHandler(new ConsoleHandler($this->output));
$logger->pushHandler($this->handler);
Guid::setLogger($logger);

$this->storage = new PDOAdapter($logger, new PDO('sqlite::memory:'));
$this->storage->migrations('up');


$this->mapper = new DirectMapper($logger, $this->storage);
$this->mapper->setOptions(options: ['class' => new StateEntity([])]);

Expand Down
7 changes: 5 additions & 2 deletions tests/Mappers/Import/MemoryMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use App\Libs\Data;
use App\Libs\Entity\StateEntity;
use App\Libs\Entity\StateInterface as iFace;
use App\Libs\Extends\ConsoleHandler;
use App\Libs\Guid;
use App\Libs\Mappers\Import\MemoryMapper;
use App\Libs\Storage\PDO\PDOAdapter;
use App\Libs\Storage\StorageInterface;
use Monolog\Handler\TestHandler;
use Monolog\Logger;
use PDO;
use PHPUnit\Framework\TestCase;
Expand All @@ -25,6 +25,7 @@ class MemoryMapperTest extends TestCase

private MemoryMapper|null $mapper = null;
private StorageInterface|null $storage = null;
protected TestHandler|null $handler = null;

public function setUp(): void
{
Expand All @@ -34,8 +35,10 @@ public function setUp(): void
$this->testMovie = require __DIR__ . '/../../Fixtures/MovieEntity.php';
$this->testEpisode = require __DIR__ . '/../../Fixtures/EpisodeEntity.php';

$this->handler = new TestHandler();
$logger = new Logger('logger');
$logger->pushHandler(new ConsoleHandler($this->output));
$logger->pushHandler($this->handler);
Guid::setLogger($logger);

$this->storage = new PDOAdapter($logger, new PDO('sqlite::memory:'));
$this->storage->migrations('up');
Expand Down
7 changes: 5 additions & 2 deletions tests/Storage/PDOAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

use App\Libs\Entity\StateEntity;
use App\Libs\Entity\StateInterface;
use App\Libs\Extends\ConsoleHandler;
use App\Libs\Guid;
use App\Libs\Storage\PDO\PDOAdapter;
use App\Libs\Storage\StorageException;
use App\Libs\Storage\StorageInterface;
use DateTimeImmutable;
use Error;
use Monolog\Handler\TestHandler;
use Monolog\Logger;
use PDO;
use PHPUnit\Framework\TestCase;
Expand All @@ -25,6 +25,7 @@ class PDOAdapterTest extends TestCase
private array $testEpisode = [];

private StorageInterface|null $storage = null;
protected TestHandler|null $handler = null;

public function setUp(): void
{
Expand All @@ -34,8 +35,10 @@ public function setUp(): void
$this->testMovie = require __DIR__ . '/../Fixtures/MovieEntity.php';
$this->testEpisode = require __DIR__ . '/../Fixtures/EpisodeEntity.php';

$this->handler = new TestHandler();
$logger = new Logger('logger');
$logger->pushHandler(new ConsoleHandler($this->output));
$logger->pushHandler($this->handler);
Guid::setLogger($logger);

$this->storage = new PDOAdapter($logger, new PDO('sqlite::memory:'));
$this->storage->migrations('up');
Expand Down

0 comments on commit 3e2795f

Please sign in to comment.