Esempio n. 1
0
 /**
  *
  * @param stdClass $item
  * @return string[]|NULL[]
  */
 protected function schemaToRow($item)
 {
     $row = [];
     $row['id'] = $item->id;
     $row['type'] = $item->type;
     switch ($item->type) {
         case 'array':
             $row['properties'] = var_Export($item->items, true);
             break;
         case 'object':
         default:
             if (isset($item->properties)) {
                 $row['properties'] = $this->propertiesToColumn($item->properties);
             }
             break;
     }
     return $row;
 }
 public function executeLookupMany(sfWebRequest $request)
 {
     sfConfig::set('sf_admin_dash', false);
     sfConfig::set('sf_web_debug', false);
     $q = Doctrine_Query::create()->from('majaxMediaGallery g')->where('g.id IN (' . implode(',', $request->getParameter('values', array())) . ')');
     $items = $q->execute();
     if ($items) {
         $ret = array('status' => 'valid');
         $ret['results'] = array();
         foreach ($items as $item) {
             $ret['results'][] = $this->objectToArray($item);
         }
     } else {
         $ret = array('status' => 'invalid');
     }
     $this->getLogger()->debug(var_Export($ret, true));
     echo json_encode($ret);
     exit(0);
     return sfView::NONE;
 }
Esempio n. 3
0
 /**
  * Função createUpdateJob
  *
  * Creates a new job in the database, if the parameter \$jobID is filled, the Job's content will be updated.
  *
  * @author Henrique Ramos <*****@*****.**>
  * @version 0.2.0
  * @since 0.1.0
  *
  * @param array[] $params F3 parameters array.
  *
  * @throws Exception If _POST parameters job_name, job_cron, job_type, job_path aren't filled or are invalid
  * @throws Exception If can't add the Job in the database
  *
  * @return array[]
  */
 public function createUpdateJob($params)
 {
     global $connectDB, $logger;
     try {
         $jobID = (!empty($params['jobID']) and is_numeric($params['jobID'])) ? $params['jobID'] : NULL;
         $job_author = 1;
         //Melhorar isso
         if (empty($_POST['job_name'])) {
             throw new \Exception(__("You need a valid name for this job."));
         }
         if (empty($_POST['job_cron'])) {
             throw new \Exception(__("We need the Cron filled."));
         }
         if (!\Cron\CronExpression::isValidExpression($_POST['job_cron'])) {
             throw new \Exception(__("We need a valid Cron syntax."));
         }
         if (empty($_POST['job_type']) or !in_array($_POST['job_type'], array('internal', 'external'))) {
             throw new \Exception(__("We need the job type filled.  Choose between \"internal\" and \"external\"."));
         }
         if (empty($_POST['job_path'])) {
             throw new \Exception(__("We need the job path filled."));
         }
         if (empty($_POST['job_status']) or !in_array($_POST['job_status'], array('active', 'disable'))) {
             throw new \Exception(__("We need the job type filled.  Choose between \"active\" and \"disable\"."));
         }
         $alertArray = $_POST['alerts'];
         if (!empty($alertArray) and !is_array($alertArray)) {
             throw new \Exception(__("Fill the \"alerts\" parameter correctly."));
         }
         $job_comment = !empty($_POST['job_comment']) ? $_POST['job_comment'] : NULL;
         $job_status = $_POST['job_status'] == 'active' ? 1 : 0;
         $job_cron = $_POST['job_cron'];
         $job_group = 1;
         //Groups::checkIfGroupExists($_POST['job_group'])?$_POST['job_group']:NULL;
         $timestamp = time();
         $connectDB->beginTransaction();
         $insertJobDatabase = $connectDB->prepare("INSERT INTO `jobs`(`job_id`, `job_name`, `job_date`, `job_cron`, `job_path`, `job_type`, `job_author`, `job_status`, `job_comment`, `job_group`, `is_running`) VALUES (:job_id,:job_name, FROM_UNIXTIME(:job_date),:job_cron,:job_path,:job_type,:job_author,:job_status,:job_comment,:job_group,0) ON DUPLICATE KEY UPDATE `job_name`=:job_name, `job_cron`=:job_cron, `job_path`=:job_path, `job_type`=:job_type, `job_status`=:job_status, `job_comment`=:job_comment, `job_group`=:job_group");
         $insertJobDatabase->bindValue(":job_id", $jobID, \PDO::PARAM_STR);
         $insertJobDatabase->bindValue(":job_name", $_POST['job_name'], \PDO::PARAM_STR);
         $insertJobDatabase->bindValue(":job_date", $timestamp, \PDO::PARAM_INT);
         $insertJobDatabase->bindValue(":job_cron", $job_cron, \PDO::PARAM_STR);
         $insertJobDatabase->bindValue(":job_path", $_POST['job_path'], \PDO::PARAM_STR);
         $insertJobDatabase->bindValue(":job_type", $_POST['job_type'], \PDO::PARAM_STR);
         $insertJobDatabase->bindValue(":job_author", $job_author, \PDO::PARAM_INT);
         $insertJobDatabase->bindValue(":job_status", $job_status, \PDO::PARAM_STR);
         $insertJobDatabase->bindValue(":job_comment", $job_comment, \PDO::PARAM_STR);
         $insertJobDatabase->bindValue(":job_group", $job_group, \PDO::PARAM_STR);
         if (!$insertJobDatabase->execute()) {
             $logger->addError(sprintf(__("MySQL Error %s"), var_Export($insertJobDatabase->errorInfo(), true)));
             throw new \Exception(sprintf(__("Problems with database insertion. Try again later. MySQL Error %s"), $insertJobDatabase->errorCode()));
         }
         $JobIDInfo = $connectDB->lastInsertId();
         foreach ($alertArray as $alertIndividual) {
             $alert = new Alert();
             $alert->addUpdateAlert($JobIDInfo, $alertIndividual);
         }
         $logger->addError(sprintf(__("About Job: {id: \"%s\" name: \"%s\", timestamp: \"%s\", path: \"%s\"}"), $JobIDInfo, $_POST['job_name'], $timestamp, $_POST['job_path']));
         //Inserir no crontab
         switch ($_POST['job_type']) {
             case 'external':
                 $logger->addInfo(sprintf(__("External Job %s"), ExternalCrawlerPath));
                 $pathToCallingJob = ExternalCrawlerPath;
                 break;
             case 'internal':
             default:
                 $logger->addInfo(sprintf(__("Internal Job %s"), InternalCrawlerPath));
                 $pathToCallingJob = InternalCrawlerPath;
                 break;
         }
         $logger->addInfo(sprintf(__("Job Info %s"), var_export($JobInfo, true)));
         $logger->addInfo(sprintf(__("CRON Expression %s"), $job_cron));
         $logger->addInfo(sprintf(__("CRON Log %s"), Zeus_Monitor_Log_Path));
         $logger->addInfo(sprintf(__("Path to call job %s"), $pathToCallingJob));
         $cronParser = \Cron\CronExpression::factory($job_cron);
         $cronMinute = !empty($cronParser->getExpression(1)) ? $cronParser->getExpression(1) : "*";
         $cronHour = !empty($cronParser->getExpression(2)) ? $cronParser->getExpression(2) : "*";
         $cronDayMonth = !empty($cronParser->getExpression(3)) ? $cronParser->getExpression(3) : "*";
         $cronMonth = !empty($cronParser->getExpression(4)) ? $cronParser->getExpression(4) : "*";
         $cronDayWeek = !empty($cronParser->getExpression(5)) ? $cronParser->getExpression(5) : "*";
         $addToCron = new \MyBuilder\Cronos\Formatter\Cron();
         $addToCron->comment(sprintf("Job %s", addslashes(htmlspecialchars($_POST['job_name']))))->job("php {$pathToCallingJob} {$JobIDInfo}")->setMinute($cronMinute)->setHour($cronHour)->setDayOfMonth($cronDayMonth)->setMonth($cronMonth)->setDayOfWeek($cronDayWeek)->setStandardOutFile('log')->appendStandardErrorToFile(Zeus_Monitor_Log_Path)->end();
         $connectDB->commit();
         if (is_null($jobID)) {
             return json_encode(array('success' => sprintf(__("Job inserted with success.<br />Please, insert this code inside your cron:<br /><code>%s</code>"), nl2br($addToCron->format()))));
         }
         return json_encode(array('success' => sprintf(__("Job updated with success.<br />Please, insert this code inside your cron:<br /><code>%s</code>"), nl2br($addToCron->format()))));
     } catch (Exception $e) {
         $connectDB->rollBack();
         throw $e;
     }
 }