protected function execute($arguments = array(), $options = array()) { $context = sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('app', $options['env'], true)); // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); $apli = new Appliance(); $serial = $apli->get_serial_number(); $this->log('[INFO] Appliance backup...' . "\n"); if ($serial) { $result = $apli->backup(true); if (!$result['success']) { if ($result['action'] == Appliance::LOGIN_BACKUP) { $result['txt'] = 'Could not login!'; } if ($result['action'] == Appliance::DB_BACKUP) { $result['txt'] = 'DB backup error...'; } if ($result['action'] == Appliance::MA_BACKUP) { $result['txt'] = 'MA backup error...'; } $reason = $result['info']; if ($result['txt']) { $reason = $result['txt']; } $message = 'The backup failed, reason: ' . $reason; $context->getEventDispatcher()->notify(new sfEvent($this->name, 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR))); $this->log('[ERR] ' . $message . "\n"); } else { $message = 'The backup process run with success.'; $context->getEventDispatcher()->notify(new sfEvent($this->name, 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::INFO))); $this->log('[INFO] ' . $message . "\n"); } } else { $this->log('[INFO] Could not be possible to do the backup because the appliance is not registered!' . "\n"); } }
public function executeJsonRestore(sfWebRequest $request) { $backup_id = $request->getParameter('backup'); $backup_size = $request->getParameter('backup_size'); $apli = new Appliance(); $method = $request->getParameter('method'); switch ($method) { case 'restore': $serial = $apli->get_serial_number(); if (!$serial) { $msg = 'Need to register first!'; $result = array('success' => false, 'agent' => 'MASTERSITE', 'action' => 'need_register', 'info' => $msg, 'error' => $msg); $error = $this->setJsonError($result); return $this->renderText($error); } $result = $apli->restore($backup_id); if (!$result['success']) { if ($result['action'] == 'check_nodes') { $result['txt'] = 'VA error...'; } } break; default: $result = array('success' => true, 'data' => array()); break; } if (!$result['success']) { $error = $this->setJsonError($result); return $this->renderText($error); } $json_encoded = json_encode($result); $this->getResponse()->setHttpHeader('Content-type', 'application/json'); return $this->renderText($json_encoded); }