public function testExecute() { $app = new App(); $app->execute(__DIR__ . '/resources/app.sqlite.test', 'github', 'qiita'); $users = Model::findAll('users'); $usermeta = Model::findAll('usermeta'); $this->assertSame($users, [['id' => '1', 'name' => 'hikouki', 'website' => 'https://qiita.com/hikouki'], ['id' => '2', 'name' => 'tarou', 'website' => 'https://qiita.com/tarou'], ['id' => '3', 'name' => 'bob', 'website' => 'https://qiita.com/bob'], ['id' => '4', 'name' => 'jon', 'website' => 'https://googlee.com/jon']]); $this->assertSame($usermeta, [['id' => '1', 'meta' => 'a:2:{s:3:"pet";s:3:"cat";s:3:"app";s:9:"qiita.com";}'], ['id' => '2', 'meta' => 'a:2:{s:3:"pet";s:3:"dog";s:3:"app";s:9:"qiita.com";}'], ['id' => '3', 'meta' => 'a:2:{s:3:"pet";s:4:"bird";s:3:"app";s:10:"google.com";}']]); }
/** * Execute. * @param $databaseFilePath Database file path. * @param $target replace target string. * @param $replace replaced string. * @return void */ public function execute($databaseFilePath, $target, $replace) { Database::load($databaseFilePath); $tables = Model::findAllTableStructure(); foreach ($tables as $table) { $rows = Model::findAll($table); foreach ($rows as &$row) { if ($this->replaceIfHit($row, $target, $replace)) { Model::updateRow($row, $table); } } } }
public function testUpdateRow() { Model::updateRow(['id' => 1, 'name' => 'stigma'], 'users'); $rows = Model::findAll("users"); $this->assertSame($rows, [['id' => '1', 'name' => 'stigma'], ['id' => '2', 'name' => 'bob'], ['id' => '3', 'name' => 'mikel'], ['id' => '4', 'name' => 'jon']]); }