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

Migrate Goal plugin update script to use Migration Factory #10808

Merged
merged 1 commit into from
Oct 30, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 23 additions & 6 deletions plugins/Goals/Updates/3.0.0-b1.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,38 @@
use Piwik\Common;
use Piwik\Updater;
use Piwik\Updates;
use Piwik\Updater\Migration\Factory as MigrationFactory;


class Updates_3_0_0_b1 extends Updates
{
public function getMigrationQueries(Updater $updater)
/**
* @var MigrationFactory
*/
private $migration;

public function __construct(MigrationFactory $factory)
{
$this->migration = $factory;
}

/**
* Here you can define one or multiple SQL statements that should be executed during the update.
* @return Updater\Migration[]
*/
public function getMigrations(Updater $updater)
{
$updateSql = array(
'ALTER TABLE `' . Common::prefixTable('goal')
. '` ADD COLUMN `description` VARCHAR(255) NOT NULL DEFAULT \'\' AFTER `name`;' => array(1060)
return array(
$this->migration->db->addColumn('goal', 'description', 'VARCHAR(255) NOT NULL DEFAULT \'\'', 'name'),
);
return $updateSql;
}

/**
* Here you can define any action that should be performed during the update. For instance executing SQL statements,
* renaming config entries, updating files, etc.
*/
public function doUpdate(Updater $updater)
{
$updater->executeMigrationQueries(__FILE__, $this->getMigrationQueries($updater));
$updater->executeMigrations(__FILE__, $this->getMigrations($updater));
}
}