-
-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60f1828
commit 9aebe9c
Showing
11 changed files
with
273 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bolt\Command; | ||
|
||
use Bolt\Utils\ListFormatHelper; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
class ClearListFormatCommand extends Command | ||
{ | ||
/** @var string */ | ||
protected static $defaultName = 'cache:clear-list-format'; | ||
|
||
/** @var ListFormatHelper */ | ||
private $listFormatHelper; | ||
|
||
public function __construct(ListFormatHelper $listFormatHelper) | ||
{ | ||
$this->listFormatHelper = $listFormatHelper; | ||
|
||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure(): void | ||
{ | ||
$this | ||
->setDescription('Clear Bolt\'s cached ListFormat data. ') | ||
->setHelp( | ||
<<<'HELP' | ||
The <info>%command.name%</info> command clears the `list_format` and `title` columns in the database. Be sure to run `bolt:update-list-format` afterwards. | ||
HELP | ||
); | ||
} | ||
|
||
/** | ||
* This method is executed after initialize(). It usually contains the logic | ||
* to execute to complete this command task. | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
$io->text('// Clearing the Bolt Content `list_format` and `title` columns.'); | ||
|
||
$success = $this->listFormatHelper->clearColumns(); | ||
|
||
if ($success) { | ||
$io->success('Cleared successfully. Be sure to run `bolt:update-list-format` next.'); | ||
} else { | ||
$io->warning('Not all the rows could be cleared successfully. Remove them manually'); | ||
} | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bolt\Command; | ||
|
||
use Bolt\Utils\ListFormatHelper; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
class UpdateListFormatCommand extends Command | ||
{ | ||
/** @var string */ | ||
protected static $defaultName = 'bolt:update-list-format'; | ||
|
||
public function __construct(ListFormatHelper $listFormatHelper) | ||
{ | ||
$this->listFormatHelper = $listFormatHelper; | ||
Check failure on line 21 in src/Command/UpdateListFormatCommand.php GitHub Actions / PHPStan
|
||
|
||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure(): void | ||
{ | ||
$this | ||
->setDescription('Update Bolt\'s cached ListFormat data. ') | ||
->setHelp( | ||
<<<'HELP' | ||
The <info>%command.name%</info> updates clears the `list_format` and `title` columns in the database. | ||
HELP | ||
); | ||
// ->addArgument('amount', InputArgument::OPTIONAL, 'The number of rows to update in one invocation', 100); | ||
|
||
} | ||
|
||
/** | ||
* This method is executed after initialize(). It usually contains the logic | ||
* to execute to complete this command task. | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
$io->text('// Clearing the Bolt Content `list_format` and `title` columns.'); | ||
|
||
$amount = 10000; | ||
|
||
$success = $this->listFormatHelper->updateColumns($amount); | ||
Check failure on line 54 in src/Command/UpdateListFormatCommand.php GitHub Actions / PHPStan
|
||
|
||
if ($success) { | ||
$io->success('Rows updated successfully.'); | ||
} else { | ||
$io->warning('Not all the rows could be cleared successfully. Remove them manually'); | ||
} | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Bolt\Utils; | ||
|
||
use Bolt\Configuration\Config; | ||
use Bolt\Repository\ContentRepository; | ||
use Doctrine\DBAL\Connection; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
|
||
class ListFormatHelper | ||
{ | ||
/** @var Config */ | ||
private $config; | ||
Check failure on line 13 in src/Utils/ListFormatHelper.php GitHub Actions / PHPStan
|
||
|
||
/** @var Connection */ | ||
private $connection; | ||
|
||
/** @var string */ | ||
private $prefix; | ||
|
||
/** @var ContentRepository */ | ||
private $contentRepository; | ||
|
||
/** @var EntityManagerInterface */ | ||
private $em; | ||
|
||
public function __construct(Config $config, Connection $connection, ContentRepository $contentRepository, string $tablePrefix = 'bolt_', EntityManagerInterface $em) | ||
{ | ||
$this->config = $config; | ||
$this->connection = $connection; | ||
$this->prefix = $tablePrefix; | ||
$this->contentRepository = $contentRepository; | ||
$this->em = $em; | ||
} | ||
|
||
public function clearColumns(): bool | ||
{ | ||
$query = sprintf('UPDATE %scontent SET title = "", list_format = ""', $this->prefix); | ||
$result = $this->connection->executeQuery($query); | ||
|
||
return (bool) $result; | ||
} | ||
|
||
public function updateColumns(int $limit = 100): bool | ||
{ | ||
$query = sprintf('SELECT id FROM %scontent WHERE title = "" OR list_format = "" LIMIT %d', $this->prefix, $limit); | ||
|
||
$rows = $this->connection->fetchAllAssociative($query); | ||
|
||
$counter = 0; | ||
|
||
foreach ($rows as $row) { | ||
$record = $this->contentRepository->findOneById($row['id']); | ||
|
||
$record->setListFormat(); | ||
$this->em->persist($record); | ||
|
||
|
||
$counter++; | ||
if ($counter > 20) { | ||
echo '.'; | ||
$this->em->flush(); | ||
$counter = 0; | ||
} | ||
|
||
} | ||
|
||
$this->em->flush(); | ||
|
||
return true; | ||
} | ||
|
||
} |
Oops, something went wrong.