Example #1
0
 protected function _execute(array $params)
 {
     $model = $params['model'];
     $orm = ORM::factory($model);
     $orm->send_search_mapping();
     Minion_CLI::write('Search mapping for model ' . Minion_CLI::color($model, 'blue') . ' updated!');
 }
Example #2
0
 public static function modify_file($file, $content, $force = FALSE, $unlink = FALSE)
 {
     if ($unlink) {
         $file_already_exists = is_file($file);
         if ($file_already_exists) {
             unlink($file);
             Minion_CLI::write(Minion_CLI::color('Removed file ' . Debug::path($file), 'light_green'));
         } else {
             Minion_CLI::write(Minion_CLI::color('File does not exist ' . Debug::path($file), 'brown'));
         }
     } elseif ($force) {
         $file_already_exists = is_file($file);
         if (!is_dir(dirname($file))) {
             mkdir(dirname($file), 0777, TRUE);
         }
         file_put_contents($file, $content);
         if ($file_already_exists) {
             Minion_CLI::write(Minion_CLI::color('Overwritten file ' . Debug::path($file), 'brown'));
         } else {
             Minion_CLI::write(Minion_CLI::color('Generated file ' . Debug::path($file), 'light_green'));
         }
     } else {
         if (is_file($file)) {
             Minion_CLI::write(Minion_CLI::color('File already exists ' . Debug::path($file), 'brown'));
         } else {
             if (!is_dir(dirname($file))) {
                 mkdir(dirname($file), 0777, TRUE);
             }
             file_put_contents($file, $content);
             Minion_CLI::write(Minion_CLI::color('Generated file ' . Debug::path($file), 'light_green'));
         }
     }
 }
Example #3
0
 protected function _execute(array $params)
 {
     $vk = Vk::instance();
     $user_ids = array();
     $message = 'У вашего объявления обновился статус!';
     $result = NULL;
     try {
         $user_ids = Utils::getNotifyUserIDs();
     } catch (Database_Exception $e) {
         Minion_CLI::write($e->getMessage());
         return;
     }
     if (count($user_ids) == 0) {
         Minion_CLI::write('no users');
         return;
     }
     try {
         $vk->login();
         $result = $vk->api('secure.sendNotification', array('user_ids' => implode($user_ids, ','), 'message' => urlencode($message), 'client_secret' => $vk->config['VK_APP_SECRET']));
     } catch (Kohana_Exception $e) {
         Minion_CLI::write($e->getMessage());
         return;
     }
     if (is_null($result)) {
         Minion_CLI::write('wtf?');
         return;
     }
     try {
         Utils::uncheckUsersNotifyByIDs($user_ids);
     } catch (Database_Exception $e) {
         Minion_CLI::write($e->getMessage());
         return;
     }
     Minion_CLI::write('done!');
 }
 protected function _execute(array $params)
 {
     $db = Database::instance(Database::$default);
     Minion_CLI::write('Exporting table structure to structure.sql');
     try {
         $rows = $db->query(Database::SELECT, 'show tables', FALSE);
         $tables = [];
         $views = [];
         foreach ($rows as $row) {
             $table = reset($row);
             $res = $db->query(Database::SELECT, 'show create table `' . $table . '`', FALSE);
             $res = $res[0];
             $schema = Arr::get($res, 'Create Table', NULL);
             if ($schema === NULL) {
                 $schema = Arr::get($res, 'Create View', NULL);
                 $schema = preg_replace('#^CREATE.*VIEW `#U', 'CREATE VIEW `', $schema);
                 if ($schema === NULL) {
                     continue;
                 }
                 $views[] = $schema . ';';
                 continue;
             }
             $tables[] = $schema . ';';
         }
         file_put_contents(Migration::config('dump') . 'structure.sql', implode("\n\n", $tables) . "\n\n" . implode("\n\n", $views));
         Minion_CLI::write('OK');
     } catch (Exception $ex) {
         Minion_CLI::write('ERROR: ' . $ex->getMessage());
     }
 }
Example #5
0
 /**
  * Task to run pending migrations
  *
  * @return null
  */
 protected function _execute(array $params)
 {
     $migrations = new MigrationManager();
     Database::$default = $params['db'];
     $this->db = Database::instance();
     $db_config = Kohana::$config->load('database')->{$params['db']};
     if (!ORM::factory('Migration')->is_installed()) {
         /**
          * Get platform from database config
          */
         $platform = strtolower($db_config['type']);
         if ('mysqli' == $platform) {
             $platform = 'mysql';
         }
         /**
          * Get SQL from file for selected platform
          */
         $file = realpath(substr(__DIR__, 0, strlen(__DIR__) - strlen('classes/Task/Db')) . 'sql/' . $platform . '.sql');
         $handle = fopen($file, 'rb');
         $sql_create = fread($handle, filesize($file));
         $this->db->query(0, $sql_create);
         $msg = Minion_CLI::color("-----------------------------\n", 'green');
         $msg .= Minion_CLI::color("| Migration table create!!! |\n", 'green');
         $msg .= Minion_CLI::color("-----------------------------\n", 'green');
         Minion_CLI::write($msg);
     }
     $migrations->migrate($params['db'], $params['step']);
 }
Example #6
0
 public function execute(array $options)
 {
     $db = $this->db_params($options['database']);
     $file = $options['file'] ? $options['file'] : Kohana::$config->load("migrations.path") . DIRECTORY_SEPARATOR . 'schema.sql';
     $command = strtr("mysqldump -u:username -p:password --skip-comments --add-drop-database --add-drop-table --no-data :database | sed 's/AUTO_INCREMENT=[0-9]*\\b//' > :file ", array(':username' => $db['username'], ':password' => $db['password'], ':database' => $db['database'], ':file' => $file));
     Minion_CLI::write('Saving structure of database "' . $db['database'] . '" to ' . Debug::path($file), 'green');
     system($command);
 }
Example #7
0
 /**
  * Execute the task
  *
  * @param array Configuration
  */
 public function execute(array $config)
 {
     try {
         $file = $this->generate($config);
         Minion_CLI::write('Migration generated: ' . $file);
     } catch (ErrorException $e) {
         Minion_CLI::write($e->getMessage());
     }
 }
Example #8
0
 /**
  * Execute the task
  *
  * @param array $options Configuration
  */
 protected function _execute(array $options)
 {
     try {
         $file = $this->generate($options);
         Minion_CLI::write('Migration generated: ' . $file);
     } catch (ErrorException $e) {
         Minion_CLI::write($e->getMessage());
     }
 }
Example #9
0
 /**
  * Task to rollback last executed migration
  *
  * @return null
  */
 protected function _execute(array $params)
 {
     $migrations = new MigrationManager();
     Database::$default = $params['db'];
     if (!ORM::factory('Migration')->is_installed()) {
         Minion_CLI::write('Migrations is not installed. Please Run the migrations.sql script in your mysql server');
         exit;
     }
     $migrations->rollback($params['db'], $params['step']);
 }
 protected function _execute(array $params)
 {
     if (!Migration::is_installed()) {
         Migration::install();
     }
     if (Migration::generate($params['name'], $params['columns']) === TRUE) {
         Minion_CLI::write('Migration \'' . $params['name'] . '\' was succefully created');
     } else {
         Minion_CLI::write('An error occured while creating migration \'' . $params['name'] . '\'');
     }
 }
 public function execute(array $options)
 {
     if ($options['force'] === NULL or 'yes' === Minion_CLI::read('This will destroy all data in the current database. Are you sure? [yes/NO]')) {
         Minion_CLI::write('Dropping Tables', 'green');
         $migrations = new Migrations(array('log' => 'Minion_CLI::write'));
         $migrations->clear_all();
         Minion_Task::factory('db:migrate')->execute($options);
     } else {
         Minion_CLI::write('Nothing done', 'brown');
     }
 }
Example #12
0
 public function increase_message_field_size()
 {
     $db = Database::instance();
     $cols = $db->list_columns($this->tbl);
     if ($cols['message']['data_type'] != 'longtext') {
         Minion_CLI::write("Increasing length of message field to LONGTEXT");
         $msgcol = $db->quote_column('message');
         $sql = "ALTER TABLE " . $db->quote_table($this->tbl) . " CHANGE {$msgcol} {$msgcol} LONGTEXT NOT NULL";
         $db->query(NULL, $sql);
     }
 }
Example #13
0
 /**
  * Task to build a new migration file
  *
  * @return null
  */
 protected function _execute(array $params)
 {
     $migrations = new MigrationManager();
     $status = $migrations->generate_migration($params['name']);
     if ($status == 0) {
         Minion_CLI::write('Migration ' . $params['name'] . ' was succefully created');
         Minion_CLI::write('Please check migrations folder');
     } else {
         Minion_CLI::write('There was an error while creating migration ' . $params['name']);
     }
 }
Example #14
0
 /**
  * Execute the task and copy the required files
  *
  * @param array $params the command options
  *
  * @return void
  */
 protected function _execute(array $params)
 {
     // Identify the vendor and destination path
     $vendor_path = $params['vendor-path'];
     $public_path = $params['public-path'];
     // Publish the twitter bootstrap js at DOCROOT/assets/js/twbs
     $this->copy_files($vendor_path . '/twbs/bootstrap/js', '/\\.js$/', $public_path . '/js/twbs');
     Minion_CLI::write(Minion_CLI::color('Published bootstrap javascripts to ' . $public_path . '/js/twbs', 'green'));
     // Publish the font-awesome font files as DOCROOT/assets/font
     $this->copy_files($vendor_path . '/fortawesome/font-awesome/font', '/^fontawesome/i', $public_path . '/font');
     Minion_CLI::write(Minion_CLI::color('Published font-awesome font to ' . $public_path . '/font', 'green'));
 }
Example #15
0
 protected function _execute(array $params)
 {
     if ($params['database'] > 0) {
         Model_Backup::factory($params['folder'] . 'db-' . date('YmdHis') . '.sql')->create()->save();
         Minion_CLI::write(__('Database backup created successfully'));
     }
     if ($params['filesystem'] > 0) {
         if (Model_Backup::factory($params['folder'] . 'filesystem-' . date('YmdHis') . '.zip')->create()) {
             Minion_CLI::write(__('Filesystem backup created successfully'));
         }
     }
 }
Example #16
0
 public function execute(array $options)
 {
     $db = $this->db_params($options['database']);
     $file = $options['file'] ? $options['file'] : Kohana::$config->load("migrations.path") . DIRECTORY_SEPARATOR . 'schema.sql';
     if ($options['force'] === NULL or 'yes' === Minion_CLI::read("This will destroy database " . $db['database'] . " Are you sure? [yes/NO]")) {
         $command = strtr("mysql -u:username -p:password :database < :file ", array(':username' => $db['username'], ':password' => $db['password'], ':database' => $db['database'], ':file' => $file));
         Minion_CLI::write('Loading data from ' . Debug::path($file) . ' to ' . $db['database'], 'green');
         system($command);
     } else {
         Minion_CLI::write('Nothing done', 'brown');
     }
 }
Example #17
0
 protected function _execute(array $params)
 {
     Minion_CLI::write('Change status videos!');
     $video = Model_Links::updatePublish();
     //
     if ($video) {
         $message = "OK";
     } else {
         $message = "Error";
     }
     Log::instance()->add(Log::INFO, "Update videos task are {$message}");
     Log::instance()->write();
 }
 protected function _execute(array $options)
 {
     $config = $this->config($options['name']);
     $config = array_merge($config, $options);
     $file = DOCROOT . $config['file'];
     $file = strtr($file, array(":timestamp" => strtotime('now')));
     Minion_CLI::write('Generating ' . json_encode($config));
     $filters = is_array($config['filter']) ? $config['filter'] : explode(',', $config['filter']);
     $content = $this->feed_content($config['model'], (array) $filters, $config['view']);
     Minion_CLI::write('Done.');
     Minion_CLI::write('Saving feed content to ' . Debug::path($file));
     file_put_contents($file, $content);
     Minion_CLI::write('Done.');
 }
Example #19
0
 protected function _execute(array $params)
 {
     try {
         if ($params['use_sleep'] == 1) {
             $status = Email_Queue::batch_send_with_sleep();
         } else {
             $status = Email_Queue::batch_send();
         }
         Minion_CLI::write('============ Report ==========');
         Minion_CLI::write(__('Total emails sent - :num', array(':num' => $status['sent'])));
         Minion_CLI::write(__('Total emails failed - :num', array(':num' => $status['failed'])));
     } catch (Exception $e) {
         Minion_CLI::write($e->getMessage());
     }
 }
 protected function _execute(array $params)
 {
     $mask = '*.php';
     if ($params['name'] !== NULL) {
         $mask = $params['name'] . '.php';
     }
     $seeds = glob(Migration::config('seeds') . $mask);
     if ($seeds !== FALSE && count($seeds)) {
         foreach ($seeds as $seed) {
             Minion_CLI::write('Seeding \'' . basename($seed, '.php') . '\'');
             include $seed;
             Minion_CLI::write('OK');
         }
     } else {
         Minion_CLI::write('Nothing to seed');
     }
 }
Example #21
0
 /**
  * Task to build a new migration file
  *
  * @return null
  */
 protected function _execute(array $params)
 {
     $migrations = new Flexiblemigrations(true);
     try {
         $model = ORM::factory('Migration');
     } catch (Database_Exception $a) {
         Minion_CLI::write('Flexible Migrations is not installed. Please Run the migrations.sql script in your mysql server');
         exit;
     }
     $status = $migrations->generate_migration($params['name']);
     if ($status == 0) {
         Minion_CLI::write('Migration ' . $params['name'] . ' was succefully created');
         Minion_CLI::write('Please check migrations folder');
     } else {
         Minion_CLI::write('There was an error while creating migration ' . $params['name']);
     }
 }
Example #22
0
 private function _resource(Resource $resource, array $route_params, $is_parent = FALSE)
 {
     $resource->param($route_params);
     $output = '';
     if (isset($route_params['id'])) {
         $output = (string) $resource->object();
     } elseif ($resource->option('singular')) {
         if ($model = $resource->option('model')) {
             $output = 'Singular model: ' . Minion_CLI::color(Jam::class_name($model), 'light_red');
         }
     } else {
         $output = 'Collection of: ' . Minion_CLI::color(Jam::class_name($resource->option('model')), 'light_red');
     }
     if ($is_parent) {
         $output = 'Parent: ' . $output;
     }
     Minion_CLI::write($output);
 }
 protected function _execute(array $params)
 {
     if (!Migration::is_installed()) {
         Migration::install();
     }
     Migration::migrate_all($messages);
     if (empty($messages)) {
         Minion_CLI::write('Nothing to migrate');
     } else {
         foreach ($messages as $message) {
             Minion_CLI::write($message[0]);
             if (isset($message[1])) {
                 Minion_CLI::write('ERROR: ' . $message[1]);
             } else {
                 Minion_CLI::write('OK');
             }
         }
     }
 }
Example #24
0
 protected function _execute(array $params)
 {
     $db_sql = Database_Helper::schema();
     $file_sql = Database_Helper::install_schema();
     $compare = new Database_Helper();
     $diff = $compare->get_updates($db_sql, $file_sql, TRUE);
     try {
         Database_Helper::insert_sql($diff);
         Cache::instance()->delete(Update::CACHE_KEY_DB_SHEMA);
         Minion_CLI::write('==============================================');
         Minion_CLI::write(__('Database schema updated successfully!'));
         Minion_CLI::write('==============================================');
     } catch (Exception $ex) {
         Minion_CLI::write('==============================================');
         Minion_CLI::write(__('Something went wrong!'));
         Minion_CLI::write('==============================================');
         Minion_CLI::write(__('Error: :message', array(':message' => $ex->getMessage())));
     }
 }
Example #25
0
 protected function _execute(array $params)
 {
     $model = $params['model'];
     $limit = $params['limit'];
     $times = $params['times'];
     $offset = $params['offset'];
     $elasticsearch = ElasticSearch::instance();
     $orm = ORM::factory($model);
     $type = $orm->_search_type();
     $total = $orm->count_all();
     // Write the header
     Minion_CLI::write('#########################################' . str_repeat('#', strlen($model)) . '##');
     Minion_CLI::write('# Bulk updating search indexes in model: ' . Minion_CLI::color($model, 'blue') . ' #');
     Minion_CLI::write('#########################################' . str_repeat('#', strlen($model)) . '##');
     Minion_CLI::write();
     Minion_CLI::write('Importing ' . $limit . ' items at a time, beginning at offset ' . $offset . ', ' . $times . ' times');
     Minion_CLI::write();
     while ($times !== 0) {
         $results = ORM::factory($model)->limit($limit)->offset($offset)->find_all();
         // Break the loop if there are no more results in the database.
         if ($results->count() <= 0) {
             break;
         }
         $documents = array();
         foreach ($results as $result) {
             $documents[] = $result->get_search_document();
         }
         $elasticsearch->add_documents($type, $documents);
         $current = $offset + $results->count();
         Minion_CLI::write('Imported: ' . $current . '/' . $total);
         $offset += $limit;
         $times -= 1;
     }
     // Write the footer
     Minion_CLI::write();
     Minion_CLI::write('##########################');
     Minion_CLI::write('# Bulk update completed! #');
     Minion_CLI::write('##########################');
 }
Example #26
0
 protected function _execute(array $params)
 {
     if (file_exists($params['file'])) {
         $file = $params['file'];
     } else {
         if (file_exists(BACKUP_PLUGIN_FOLDER . $params['file'])) {
             $file = BACKUP_PLUGIN_FOLDER . $params['file'];
         } else {
             if (file_exists(DOCROOT . $params['file'])) {
                 $file = DOCROOT . $params['file'];
             } else {
                 Minion_CLI::write(__('File :file not found', array(':file' => $params['file'])));
                 exit;
             }
         }
     }
     try {
         $backup = Model_Backup::factory($file)->restore();
         Minion_CLI::write(__('Backup from file :file restored successfully', array(':file' => $file)));
     } catch (Exception $e) {
         Minion_CLI::write($e->getMessage());
     }
 }
Example #27
0
 /**
  * Task to rollback last executed migration
  *
  * @return null
  */
 protected function _execute(array $params)
 {
     $migrations = new Flexiblemigrations(true);
     try {
         $model = ORM::factory('Migration');
     } catch (Database_Exception $a) {
         Minion_CLI::write('Flexible Migrations is not installed. Please Run the migrations.sql script in your mysql server');
         exit;
     }
     $messages = $migrations->rollback();
     if (empty($messages)) {
         Minion_CLI::write("There's no migration to rollback");
     } else {
         foreach ($messages as $message) {
             if (key($message) == 0) {
                 Minion_CLI::write($message[0]);
             } else {
                 Minion_CLI::write($message[key($message)]);
                 Minion_CLI::write("ERROR");
             }
         }
     }
 }
Example #28
0
 protected function _execute(array $params)
 {
     $source = CMS_MODPATH;
     if (!is_dir($source)) {
         Minion_CLI::write('============ No Submodules ==========');
         return;
     }
     $iterator = new \DirectoryIterator($source);
     foreach ($iterator as $item) {
         if (!$item->isDir() or $item->isDot()) {
             continue;
         }
         $file = CMS_MODPATH . $item->getBasename() . DIRECTORY_SEPARATOR . '.git';
         if (file_exists($file)) {
             continue;
         }
         $content = "gitdir: ../../../.git/modules/vendor/kodicms/{$item->getBasename()}";
         $fp = fopen($file, "wb");
         fwrite($fp, $content);
         fclose($fp);
         Minion_CLI::write('Create .git file for submodule ' . $item->getBasename());
     }
 }
 public function execute(array $options)
 {
     $options['start_date'] = date('Y-m-d', strtotime($options['start_date']));
     $options['end_date'] = date('Y-m-d', strtotime($options['end_date']));
     $result = $options['result'];
     unset($options['result']);
     $report = Report::factory('googleanalytics');
     $report_params = array();
     foreach ($options as $key => $value) {
         if ($value) {
             $report->{$key}($value);
             $report_params[] = "{$key}: {$value}";
         }
     }
     switch ($result) {
         case 'total':
             Minion_CLI::write('Total: ' . $report->total() . ' For ' . join(', ', $report_params));
             break;
         case 'rows':
             Minion_CLI::write('For ' . join(', ', $report_params) . ' Rows: ' . print_r($report->rows(), TRUE));
             break;
     }
 }
Example #30
0
 protected function _execute(array $params)
 {
     if ($params['type'] === NULL) {
         $params['type'] = Minion_CLI::read(__('Please enter cache type foe clear (:types)', array(':types' => implode(', ', array('all', 'file', 'routes', 'profiler', CACHE_TYPE)))));
     }
     switch ($params['type']) {
         case 'file':
             Cache::clear_file();
             break;
         case 'routes':
             Cache::clear_routes();
             break;
         case 'profiler':
             Cache::clear_profiler();
             break;
         case CACHE_TYPE:
             Cache::instance()->delete_all();
             break;
         default:
             Cache::clear_all();
             break;
     }
     Minion_CLI::write('============ Cache ' . $params['type'] . ' cleared ==========');
 }