-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
console
executable file
·61 lines (52 loc) · 2.31 KB
/
console
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env php
<?php
declare(strict_types = 1);
use Externals\Application\Command\DbCommand;
use Externals\Email\EmailContentParser;
use Externals\Email\EmailRepository;
use Externals\EmailSynchronizer;
use Externals\NotFound;
use Psr\Container\ContainerInterface;
use Silly\Application;
use Symfony\Component\Console\Output\OutputInterface;
use ZBateson\MailMimeParser\MailMimeParser;
/** @var ContainerInterface $container */
$container = require __DIR__ . '/config/bootstrap.php';
$cli = new Application();
$cli->useContainer($container, true, true);
$cli->command('db [--force]', [DbCommand::class, 'setup']);
$cli->command('db-purge [--force]', [DbCommand::class, 'purge']);
$cli->command('db-truncate [--force]', [DbCommand::class, 'truncate']);
$cli->command('sync [max]', function (EmailSynchronizer $synchronizer, OutputInterface $output, int $max = null) {
$start = microtime(true);
$synchronizer->synchronize($max);
$time = microtime(true) - $start;
$output->writeln("<comment>Emails have been synchronized in $time seconds</comment>");
});
$cli->command('refresh-threads', function (EmailRepository $repository, OutputInterface $output) {
$start = microtime(true);
$repository->refreshThreads();
$time = microtime(true) - $start;
$output->writeln("<comment>Threads have been refreshed in $time seconds</comment>");
});
$cli->command('reparse', function (EmailRepository $repository, EmailContentParser $parser, OutputInterface $output) {
$start = microtime(true);
$maxNumber = $repository->getLastEmailNumber();
for ($number = $maxNumber; $number > 0; $number--) { // from most recent to first
try {
$email = $repository->getByNumber($number);
} catch (NotFound) {
continue;
}
$parsedDocument = (new MailMimeParser)->parse($email->getSource(), false);
$content = $parser->parse((string) $parsedDocument->getTextContent());
$repository->updateContent($email->getId(), $content);
$output->writeln("<info>Updated email {$number}</info>");
}
$time = microtime(true) - $start;
$output->writeln("<comment>Emails have been reparsed in $time seconds</comment>");
});
$cli->command('container:get id', function (string $id, ContainerInterface $container) {
var_dump($container->get($id));
});
$cli->run();