public function runAction() { $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; $request = $this->getRequest(); $id = $request->getParam('id'); $cache = MyDiff_Cache::init(); $comparison = $cache->load('comparison' . $id); $options = $cache->load('options' . $id); if (!$id || !$comparison || !$options) { throw new MyDiff_Exception("Missing options, please go back and try again."); } // Remove tables not submitted foreach ($comparison->databases as $i => $database) { $database->useTables(array_keys($options['database'][$i]['table'])); $database->connect(); } // Do compare types if (isset($options['type']['schema'])) { $comparison->schema(); } if (isset($options['type']['data'])) { $comparison->data(); // Build a list of rows that have changed $data = array(); $tables = array($comparison->databases[0]->getTables(), $comparison->databases[1]->getTables()); foreach ($tables[0] as $tableName => $table) { if (!$table->hasDiffs('MyDiff_Diff_Table_New')) { $rows = array($tables[0][$tableName]->getRows(), isset($tables[1][$tableName]) ? $tables[1][$tableName]->getRows() : array()); // remove values that don't exist in original if (!empty($rows[0]) && !empty($rows[1])) { foreach ($rows[1] as &$row) { $row->data = array_intersect_key($row->data, reset($rows[0])->data); } } $rows = array_merge($rows[0], $rows[1]); $data[] = array('table' => $table, 'rows' => $rows); } } $this->view->data = $data; } $this->view->comparison = $comparison; $this->view->options = $options; $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = $endtime - $starttime; $this->view->id = $id; $this->view->totaltime = $totaltime; $this->view->totalmem = memory_get_peak_usage(true); }
public function runAction() { $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; $request = $this->getRequest(); $id = $request->getParam('id'); $cache = MyDiff_Cache::init(); $comparison = $cache->load('comparison' . $id); $options = $cache->load('options' . $id); if (!$id || !$comparison || !$options) { throw new MyDiff_Exception("Missing options, please go back and try again."); } // Remove tables not submitted foreach ($comparison->databases as $i => $database) { $database->useTables(array_keys($options['database'][$i]['table'])); $database->connect(); } if (!is_numeric($options['type']['srcdb'])) { return false; // can't happen } // Select source db $dbcnt = count($comparison->databases); $comparison->sourcedb = $comparison->databases[$options['type']['srcdb']]; for ($i = 0; $i < $dbcnt; $i++) { // for multiple target db next implementation if ($i != $options['type']['srcdb']) { $comparison->targetdb = $comparison->databases[$i]; } } $upFile = new UpdateFile($comparison, $options); // Do compare types if (isset($options['type']['schema'])) { $comparison->schema($comparison->targetdb, $comparison->sourcedb); $upFile->writeSchema(); } if (isset($options['type']['data'])) { $showChanges = isset($options['type']['showchanges']); $comparison->data(isset($options['type']['replace']), $options['type']['algorithm'], $upFile, $showChanges, $comparison->targetdb, $comparison->sourcedb); if ($showChanges) { // Build a list of rows that have changed $data = array(); $tables = array($comparison->targetdb->getTables(), $comparison->sourcedb->getTables()); foreach ($tables[0] as $tableName => $table) { if (!$table->hasDiffs('MyDiff_Diff_Table_New')) { $rows = array($tables[0][$tableName]->getRows(), isset($tables[1][$tableName]) ? $tables[1][$tableName]->getRows() : array()); // remove values that don't exist in original if (!isset($options['type']['allfields']) && !empty($rows[0]) && !empty($rows[1])) { foreach ($rows[1] as &$row) { $row->data = array_intersect_key($row->data, reset($rows[0])->data); } } $rows = array_merge($rows[0], $rows[1]); $data[] = array('table' => $table, 'rows' => $rows); } } // fill rows for new tables foreach ($tables[1] as $tableName => $table) { if ($table->hasDiffs('MyDiff_Diff_Table_New')) { $rows = $tables[1][$tableName]->getRows(); $data[] = array('table' => $table, 'rows' => $rows); } } $this->view->data = $data; } } $upFile->closeFile(); unset($upFile); $this->view->comparison = $comparison; $this->view->options = $options; $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = $endtime - $starttime; $this->view->id = $id; $this->view->totaltime = $totaltime; $this->view->totalmem = memory_get_peak_usage(true); }