Пример #1
0
 /**
  * Execute this command.
  *
  * @return int|void
  */
 protected function doExecute()
 {
     $type = $this->getOption('s') ? 'sql' : 'yaml';
     $model = new SchemaModel();
     if ($this->getOption('a')) {
         $profiles = ProfileHelper::getAllProfiles();
     } else {
         $profiles = $this->io->getArguments() ?: array(ProfileHelper::getProfile());
     }
     $config = Factory::getConfig();
     foreach ($profiles as $profile) {
         $config->set('profile', $profile);
         // Check schema.
         $path = $model->getPath($type);
         if (file_exists($path) && !$this->getOption('y')) {
             $prompter = new BooleanPrompter(sprintf('Schema file <info>%s</info> exists, do you want to override it? [Y/n]: ', $profile));
             if (!$prompter->ask()) {
                 $this->out('cancelled.');
                 return;
             }
         }
         // Exporting
         $this->out()->out('<comment>Exporting</comment> profile schema: <info>' . $profile . '</info>');
         $model->export($type);
         $this->out()->out(sprintf('Schema file dumped to: <info>%s</info>', $model->getState()->get('dump.path')));
     }
     /*
     $yaml = $this->getOption('yaml');
     
     $exporter = $yaml ? new YamlExporter : new SqlExporter;
     
     $result = $exporter->export();
     
     $config = \JFactory::getConfig();
     
     $file = 'site-' . $config->get('db') . '-' . date('Y-m-d-H-i-s');
     
     if ($yaml)
     {
     	$file .= '.yml';
     }
     else
     {
     	$file .= '.sql';
     }
     
     $file = JCONSOLE . '/jconsole/resource/sql/export/' . ($yaml ? 'yaml/' : '') . $file;
     
     \JFile::write($file, $result);
     
     $this->out()->out(sprintf('Sql file dumped to: %s', $file));
     */
 }
Пример #2
0
 /**
  * Execute this command.
  *
  * @return int|void
  */
 protected function doExecute()
 {
     $tableModel = new Table();
     if ($this->getOption('a')) {
         $profiles = ProfileHelper::getAllProfiles();
     } else {
         $profiles = $this->io->getArguments() ?: array(ProfileHelper::getProfile());
     }
     $config = Factory::getConfig();
     foreach ($profiles as $profile) {
         $config->set('profile', $profile);
         $tableModel->sync();
         $path = $tableModel->getState()->get('track.save.path');
         $this->out()->out('Sync all tracking status to: ' . $path);
     }
     return;
 }
Пример #3
0
 /**
  * getItems
  *
  * @return array
  */
 public function getItems()
 {
     $config = Factory::getConfig();
     $current = $config->get('profile', 'default');
     $profiles = new \FilesystemIterator(SQLSYNC_PROFILE, \FilesystemIterator::SKIP_DOTS);
     $items = array();
     foreach ($profiles as $profile) {
         if ($profile->isFile()) {
             continue;
         }
         $item = new \Stdclass();
         $item->title = $profile->getBasename();
         $item->is_current = $current == $item->title;
         $item->current_version = '';
         $items[] = $item;
     }
     return $items;
 }
Пример #4
0
 /**
  * getProfile
  *
  * @return mixed
  */
 public static function getProfile()
 {
     $config = Factory::getConfig();
     return $config->get('profile', 'default');
 }
Пример #5
0
 /**
  * Execute this command.
  *
  * @throws \RuntimeException
  * @return int|void
  */
 protected function doExecute()
 {
     $type = $this->getOption('s') ? 'sql' : 'yaml';
     $model = new SchemaModel();
     $path = $model->getPath($type);
     if (file_exists($path) && !$this->getOption('y')) {
         $prompter = new BooleanPrompter('This action will compare and update your sql schema [Y/n]: ');
         if (!$prompter->ask()) {
             $this->out('cancelled.');
             return;
         }
     } elseif (!file_exists($path)) {
         throw new \RuntimeException('Schema file not exists.');
     }
     $force = $this->getOption('f');
     if ($force) {
         throw new \RuntimeException('Sorry, force mode not prepare yet...');
     }
     $state = $model->getState();
     if ($this->getOption('a')) {
         $profiles = ProfileHelper::getAllProfiles();
     } else {
         $profiles = $this->io->getArguments() ?: array(ProfileHelper::getProfile());
     }
     $config = Factory::getConfig();
     foreach ($profiles as $profile) {
         $config->set('profile', $profile);
         // Backup
         $this->out()->out(sprintf('<comment>Backing up</comment> profile <info>%s</info> ...', $profile));
         $model->backup();
         $this->out()->out(sprintf('Schema file backup to: %s', $model->getState()->get('dump.path')));
         // Import
         $this->out()->out(sprintf('<option>Importing</option> profile schema: <info>%s</info> ...', $profile));
         $model->import($force, $type);
         $this->out()->out(sprintf('Schema file dumped to: %s', $model->getState()->get('dump.path')));
         // Report
         $analyze = $state->get('import.analyze');
         foreach ($analyze as $table => $schema) {
             $this->out()->out($table . ':');
             foreach ($schema as $action => $count) {
                 $this->out('    ' . $action . ': ' . $count);
             }
         }
     }
     return;
 }