/** * export * * @param bool $ignoreTrack * @param bool $prefixOnly * * @return mixed|string */ public function export($ignoreTrack = false, $prefixOnly = false) { $tableObject = new Table(); $trackObject = new Track(); $tables = $prefixOnly ? $tableObject->listSite() : $tableObject->listAll(); $track = $trackObject->getTrackList(); $sql = array(); $this->tableCount = 0; $this->rowCount = 0; foreach ($tables as $table) { $trackStatus = $track->get('table.' . $table, 'none'); if ($trackStatus == 'none' && !$ignoreTrack) { continue; } $sql[] = $this->queryHelper->dropTable($table); $sql[] = $this->getCreateTable($table); $this->tableCount++; if ($trackStatus == 'all' || $ignoreTrack) { $insert = $this->getInserts($table); if ($insert) { $sql[] = $insert; } } } $this->state->set('dump.count.tables', $this->tableCount); $this->state->set('dump.count.rows', $this->rowCount); return implode(";\n\n", $sql); }
/** * export * * @param bool $ignoreTrack * @param bool $prefixOnly * @param bool $text * * @return mixed|string */ public function export($ignoreTrack = false, $prefixOnly = false, $text = true) { $tableObject = new Table(); $trackObject = new Track(); $tables = $prefixOnly ? $tableObject->listSite() : $tableObject->listAll(); $track = $trackObject->getTrackList(); $result = array(); $this->tableCount = 0; $this->rowCount = 0; foreach ($tables as $table) { $trackStatus = $track->get('table.' . $table, 'none'); if ($trackStatus == 'none' && !$ignoreTrack) { continue; } $result[$table] = $this->getCreateTable($table); $this->tableCount++; if ($trackStatus == 'all' || $ignoreTrack) { $insert = $this->getInserts($table); if ($insert) { $result[$table] = array_merge($result[$table], $insert); } } } $this->state->set('dump.count.tables', $this->tableCount); $this->state->set('dump.count.rows', $this->rowCount); $dumper = new Dumper(); $result = json_decode(json_encode($result), true); return $text ? $dumper->dump($result, 3, 0, false, true) : $result; }
/** * Execute this command. * * @return int|void */ protected function doExecute() { $track = new Track(); $args = $this->io->getArguments(); $all = $this->getOption('a'); $site = $this->getOption('s'); if (empty($args[0]) && !$all && !$site) { $this->out()->out('Missing argument 1 <table_name> or -a|--all, -s|--site.'); return; } if ($all && $site) { $this->out()->out('Do you want to track tables of all or just this site?'); return; } $tableObject = new Table(); if ($all) { $tables = $tableObject->listAll(); } elseif ($site) { $tables = $tableObject->listSite(); } else { $tables = array($args[0]); } $track->setTrack($tables, $this->status); if (count($tables) > 1) { $name = count($tables) . ' tables'; } else { $name = $tables[0]; } $this->out()->out(sprintf('Set %s tracking %s.', $name, $this->status)); }
/** * sync * * @return bool */ public function sync() { $statusList = $this->status(); $path = ProfileHelper::getPath() . '/track.yml'; $trackList = array(); foreach ($statusList as $status) { $trackList['table'][$status['table']] = $status['status']; } $track = new Registry($trackList); $trackModel = new Track(); $trackModel->saveTrackList($track); $this->state->set('track.save.path', $trackModel->getState()->get('track.save.path')); return true; }