diff --git a/.travis.yml b/.travis.yml index 6f76c49..a5b8b81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,31 +1,32 @@ language: php php: -- 5.3 + - 5.4 + - 5.4 + - 5.3 env: + global: + - PLUGIN_NAME=SiteMigrator matrix: - - TEST_SUITE=CoreTests MYSQL_ADAPTER=PDO_MYSQL - TEST_SUITE=PluginTests MYSQL_ADAPTER=PDO_MYSQL script: ./travis.sh install: - - TEST_PIWIK_VERSION=$(wget builds.piwik.org/LATEST -q -O -) - - TEST_PIWIK_VERSION=`echo $TEST_PIWIK_VERSION | tr -d ' ' | tr -d '\n'` - - mkdir SiteMigrator - - cp -R !(SiteMigrator) SiteMigrator - - cp -R .git/ SiteMigrator/ - - git clone https://github.com/piwik/piwik.git piwik + - mkdir $PLUGIN_NAME + - cp -R !($PLUGIN_NAME) $PLUGIN_NAME + - cp -R .git/ $PLUGIN_NAME/ + - git clone https://github.com/piwik/piwik.git piwik --depth=1 - cd piwik - - git checkout "$TEST_PIWIK_VERSION" + - git checkout master - git submodule init - git submodule update || true - composer self-update - composer install - - rm -rf plugins/SiteMigrator + - rm -rf plugins/$PLUGIN_NAME - cd ../ - - mv SiteMigrator piwik/plugins + - mv $PLUGIN_NAME piwik/plugins before_script: - cd piwik @@ -34,8 +35,6 @@ before_script: - mysql -e 'create database piwik_tests;' - ./tests/travis/prepare.sh - ./tests/travis/setup_webserver.sh - - wget https://raw.github.com/piwik/piwik-tests-plugins/master/activateplugin.php - - php activateplugin.php SiteMigrator - cd tests/PHPUnit after_script: diff --git a/Commands/MigrateSite.php b/Commands/MigrateSite.php index ec35379..bd3e31e 100644 --- a/Commands/MigrateSite.php +++ b/Commands/MigrateSite.php @@ -218,7 +218,7 @@ protected function migrateRawData( } if ($dateTo = $input->getOption('date-to')) { $dateTo = new \DateTime($dateTo); - $visitMigrator->andWhere('visit_last_action_time', $dateTo->format('Y-m-d'), '<'); + $visitMigrator->andWhere('visit_last_action_time', $dateTo->format('Y-m-d'), '<='); } $output->writeln('Migrating raw data... '); diff --git a/README.md b/README.md index 9daac16..5348017 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,66 @@ ## Description -Add your plugin description here. +This plugin allows to migrate sites between Piwik instances. + +## Usage + +Migration can be started from CLI by typing + +`./console migrate:site idSite` + +There is only one argument: idSite. + +Please run + +`./console migrate:site --help` + +To get a full list of options. + +__Usage:__ + migrate:site [--skip-archived] [--skip-raw] [-H|--host="..."] [-U|--username="..."] [-P|--password="..."] [-N|--dbname="..."] [--prefix="..."] [--port="..."] [-F|--date-from="..."] [-T|--date-to="..."] [-I|--new-id-site="..."] idSite + +__Arguments:__ + idSite Site id + +__Options:__ + --skip-archived Skip migration of archived data + --skip-raw Skip migration of raw data + --host (-H) Destination database host + --username (-U) Destination database username + --password (-P) Destination database password + --dbname (-N) Destination database name + --prefix Destination database table prefix (default: "piwik_") + --port Destination database port (default: "3306") + --date-from (-F) Start date from which data should be migrated + --date-to (-T) Start date from which data should be migrated + --new-id-site (-I) New site id, if provided site config will not be migrated, raw and archive data will be copied into existing site + --help (-h) Display this help message. + --quiet (-q) Do not output any message. + --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug + --version (-V) Display this application version. + --ansi Force ANSI output. + --no-ansi Disable ANSI output. + --no-interaction (-n) Do not ask any interactive question. + --piwik-domain Piwik URL (protocol and domain) eg. "http://piwik.example.org" ## FAQ -__My question?__ -My answer +__How can I migrate data between two dates?__ +You can use command options: --date-from and --date-to + +__How can I migrate data to an existing page?__ +Please make sure that the config of the new site id is present and it is in sync with the config of the old file (custom vars, goals, etc). +Please check also if the site log is empty (both raw and archive). + +If both above conditions are met run the migrate:site command with the =I|--new-site-id param - this will skip config migration and will go straightly to raw data log and archive migration. ## Changelog -Here goes the changelog text. +__v0.0.1__ +- First working version + ## Support -Please direct any feedback to ... \ No newline at end of file +Please direct any feedback to contact@piwik.pro \ No newline at end of file diff --git a/Test/ConverstaionMigratorTest.php b/Test/ConverstaionMigratorTest.php deleted file mode 100644 index c96880d..0000000 --- a/Test/ConverstaionMigratorTest.php +++ /dev/null @@ -1,165 +0,0 @@ -reset(); - } - - protected function reset() - { - $this->siteMap = $this->getMock('Piwik\Plugins\SiteMigrator\Model\IdMap', array('add', 'translate')); - $this->idMapCollection = $idMapCollection = $this->getMock( - 'Piwik\Plugins\SiteMigrator\Model\IdMapCollection', - array('getSiteMap', 'getActionMap') - ); - - $this->adapter = $this->getMock( - 'Zend_Db_Adapter_Pdo_Mysql', - array('fetchRow', 'fetchAll', 'fetchCol', 'prepare', 'query'), - array(), - '', - false - ); - $this->fromDbHelper = $this->getMock( - 'Piwik\Plugins\SiteMigrator\Helper\DBHelper', - array('executeInsert', 'lastInsertId', 'getAdapter', 'prefixTable'), - array(), - '', - false - ); - - $this->toDbHelper = $this->getMock( - 'Piwik\Plugins\SiteMigrator\Helper\DBHelper', - array('executeInsert', 'lastInsertId', 'getAdapter', 'prefixTable', 'acquireLock', 'releaseLock'), - array(), - '', - false - ); - - $this->statement = $this->getMock( - 'Zend_Db_Statement_Pdo', - array('execute', 'fetch'), - array(), - '', - false - ); - - $this->archiveMigrator = new ArchiveMigrator($this->fromDbHelper, $this->toDbHelper, $this->idMapCollection); - - } - - - public function test_getArchiveList() - { - $prefixedArchives = array( - 'piwik_archive_num_01_2013', - 'piwik_archive_num_02_2013', - ); - - $archives = array( - 'archive_num_01_2013', - 'archive_num_02_2013', - ); - - $this->setupDbHelperGetAdapter($this->fromDbHelper); - $this->fromDbHelper->expects($this->once())->method('prefixTable')->will($this->returnValue('piwik_')); - $this->adapter->expects($this->once())->method('fetchCol')->will($this->returnValue($prefixedArchives)); - - $list = $this->archiveMigrator->getArchiveList(); - - foreach ($list as $k => $archive) { - $this->assertEquals($archive, $archives[$k]); - } - } - - public function test_migrateArchive() - { - $idSite = 1; - $this->setupDbHelperGetAdapter($this->toDbHelper); - $this->setupDbHelperGetAdapter($this->fromDbHelper); - - $this->adapter->expects($this->exactly(2))->method('fetchCol')->will($this->onConsecutiveCalls( - array(), - array(321) - )); - - $this->toDbHelper->expects($this->exactly(3))->method('prefixTable')->will($this->returnValue('piwik_')); - $this->fromDbHelper->expects($this->exactly(2))->method('prefixTable')->will($this->returnValue('piwik_')); - $this->adapter->expects($this->once())->method('prepare')->will($this->returnValue($this->statement)); - $this->statement->expects($this->once())->method('execute')->with(array($idSite)); - $this->statement->expects($this->exactly(2))->method('fetch')->will($this->onConsecutiveCalls( - array('idarchive' => 123, 'idsite' => $idSite, 'data' => 'dummyData', 'name' => 'dummyArchive'), - null - )); - - - $this->toDbHelper->expects($this->once())->method('acquireLock')->will($this->returnValue(true)); - $this->toDbHelper->expects($this->once())->method('releaseLock')->will($this->returnValue(true)); - $this->toDbHelper->expects($this->once())->method('executeInsert')->will($this->returnValue(true)); - $this->idMapCollection->expects($this->once())->method('getSiteMap')->with()->will($this->returnValue($this->siteMap)); - $this->siteMap->expects($this->once())->method('translate')->with($idSite)->will($this->returnValue(2)); - - $this->archiveMigrator->migrateArchive('archive_num_01_2013', $idSite); - } - - - protected function setupDbHelperGetAdapter(\PHPUnit_Framework_MockObject_MockObject $adapter) - { - $adapter->expects($this->atLeastOnce())->method('getAdapter')->with()->will( - $this->returnValue($this->adapter) - ); - } - -} \ No newline at end of file