Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable13] Emit event when running ./occ db:add-missing-indices #9620

Merged
merged 1 commit into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions core/Command/Db/AddMissingIndices.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

/**
* Class AddMissingIndices
Expand All @@ -41,12 +43,14 @@ class AddMissingIndices extends Command {
/** @var IDBConnection */
private $connection;

/**
* @param IDBConnection $connection
*/
public function __construct(IDBConnection $connection) {
$this->connection = $connection;
/** @var EventDispatcherInterface */
private $dispatcher;

public function __construct(IDBConnection $connection, EventDispatcherInterface $dispatcher) {
parent::__construct();

$this->connection = $connection;
$this->dispatcher = $dispatcher;
}

protected function configure() {
Expand All @@ -58,6 +62,9 @@ protected function configure() {
protected function execute(InputInterface $input, OutputInterface $output) {
$this->addShareTableIndicies($output);

// Dispatch event so apps can also update indexes if needed
$event = new GenericEvent($output);
$this->dispatcher->dispatch(IDBConnection::ADD_MISSING_INDEXES_EVENT, $event);
}

/**
Expand All @@ -73,8 +80,8 @@ private function addShareTableIndicies(OutputInterface $output) {
$schema = new SchemaWrapper($this->connection);
$updated = false;

if ($schema->hasTable("share")) {
$table = $schema->getTable("share");
if ($schema->hasTable('share')) {
$table = $schema->getTable('share');
if (!$table->hasIndex('share_with_index')) {
$output->writeln('<info>Adding additional index to the share table, this can take some time...</info>');
$table->addIndex(['share_with'], 'share_with_index');
Expand Down
2 changes: 1 addition & 1 deletion core/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
$application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig())));
$application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->getLogger()));
$application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->getDatabaseConnection()));
$application->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->getDatabaseConnection()));
$application->add(new OC\Core\Command\Db\AddMissingIndices(\OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher()));
$application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->getDatabaseConnection()));
$application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->getDatabaseConnection()));
$application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->getDatabaseConnection()));
Expand Down
3 changes: 3 additions & 0 deletions lib/public/IDBConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
* @since 6.0.0
*/
interface IDBConnection {

const ADD_MISSING_INDEXES_EVENT = self::class . '::ADD_MISSING_INDEXES';

/**
* Gets the QueryBuilder for the connection.
*
Expand Down