Exemple #1
0
 /**
  * Sync the database to the model classes
  */
 public function import()
 {
     $tables = func_get_args();
     if (empty($tables)) {
         throw new \Exception("No table was specified for import");
     }
     foreach ($tables as $table_name) {
         // Find class name and metadata etc
         $class_name = \Admin::getClassForTable($table_name);
         if ($class_name === false) {
             $this->writeAndLog("Import error: Class could not be found for table '{$table_name}'", "error");
             continue;
         }
         // Import the data
         \Cli::write("Importing {$table_name}...");
         try {
             $import_result = \CMF\Utils\Importer::importUrl($class_name, \Input::post('import_url'));
             if (@$import_result['success']) {
                 $this->writeAndLog("Successfully imported {$table_name}", "info", "green");
             } else {
                 $this->writeAndLog("Error importing {$table_name}: " . @$import_result['message'] ?: "Unknown error importing {$table_name}", "error");
             }
         } catch (\Exception $e) {
             $this->writeAndLog("Error importing {$table_name}: " . $e->getMessage(), "error");
         }
     }
 }
Exemple #2
0
 public function action_url($table_name)
 {
     // Find class name and metadata etc
     $class_name = \Admin::getClassForTable($table_name);
     if ($class_name === false) {
         return $this->show404(null, "type");
     }
     // Import the data
     $this->import_result = \CMF\Utils\Importer::importUrl($class_name, \Input::post('import_url'));
     // If success, redirect back with message
     if (isset($this->import_result['success']) && $this->import_result['success']) {
         \Session::set_flash('main_alert', array('attributes' => array('class' => 'alert-success'), 'msg' => isset($this->import_result['message']) ? $this->import_result['message'] : \Lang::get('admin.messages.import_success')));
         \Response::redirect("/admin/{$table_name}", 'location');
     }
     // No success, damn!
     \Session::set_flash('main_alert', array('attributes' => array('class' => 'alert-danger'), 'msg' => isset($this->import_result['message']) ? $this->import_result['message'] : \Lang::get('admin.errors.actions.import')));
     \Response::redirect_back("/admin/{$table_name}");
 }