Ejemplo n.º 1
0
 /**
  * Audit resource data
  *
  * @param   object   $job  \Components\Cron\Models\Job
  * @return  boolean
  */
 public function auditResourceData(\Components\Cron\Models\Job $job)
 {
     $params = $job->params;
     // Determine parameters
     $limit = intval($params->get('audit_limit', 500));
     $interval = strtoupper($params->get('audit_frequency', '1 MONTH'));
     $now = Date::toSql();
     // Get records needing to be processed
     $db = App::get('db');
     /*$db->setQuery(
     			"SELECT DISTINCT(r.id), r.*
     			FROM `#__resources` AS r
     			LEFT JOIN `#__audit_results` AS a ON a.scope_id=r.id
     			WHERE (a.scope=" . $db->quote('resource') . " OR a.scope='' OR a.scope IS NULL)
     			AND (DATE_ADD(a.processed, INTERVAL " . $interval . ") < " . $db->quote($now) . " OR a.processed = '0000-00-00 00:00:00' OR a.processed IS NULL)
     			LIMIT 0," . $limit
     		);
     		$data = $db->loadAssocList();*/
     // Get records that haven't been processed
     $db->setQuery("SELECT r.*\n\t\t\tFROM `#__resources` AS r\n\t\t\tWHERE r.id NOT IN (\n\t\t\t\tSELECT a.scope_id\n\t\t\t\tFROM `#__audit_results` AS a\n\t\t\t\tWHERE a.scope=" . $db->quote('resource') . "\n\t\t\t)\n\t\t\tLIMIT 0," . $limit);
     $data = $db->loadAssocList();
     $unprocessed = count($data);
     // If we didn't reach the limit
     // Get records that need to be re-processed
     if ($unprocessed < $limit) {
         $nlimit = $limit - $unprocessed;
         $nlimit = $nlimit > 0 ? $nlimit : 1;
         $db->setQuery("SELECT r.*\n\t\t\t\tFROM `#__resources` AS r\n\t\t\t\tWHERE r.id IN (\n\t\t\t\t\tSELECT a.scope_id\n\t\t\t\t\tFROM `#__audit_results` AS a\n\t\t\t\t\tWHERE a.scope=" . $db->quote('resource') . "\n\t\t\t\t\tAND DATE_ADD(a.processed, INTERVAL " . $interval . ") < " . $db->quote($now) . "\n\t\t\t\t)\n\t\t\t\tLIMIT 0," . $nlimit);
         if ($data2 = $db->loadAssocList()) {
             $data = $data + $data2;
         }
     }
     // Process records
     if (count($data) > 0) {
         //$nxt = Date::of('now')->modify('+' . $interval)->toSql();
         include_once PATH_CORE . '/components/com_resources/helpers/tests/links.php';
         $auditor = new \Hubzero\Content\Auditor('resource');
         $auditor->registerTest(new \Components\Resources\Helpers\Tests\Links());
         $results = $auditor->check($data);
         // Loop through each record
         foreach ($results as $reportcard) {
             // Loop through each test result and save to the database
             foreach ($reportcard['tests'] as $result) {
                 $prev = Hubzero\Content\Auditor\Result::oneByScope($result->get('scope'), $result->get('scope_id'));
                 if ($prev->get('id')) {
                     $result->set('id', $prev->get('id'));
                 }
                 //$result->set('next_process', $nxt);
                 $result->save();
             }
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Check resource paths
  */
 public function checkTask()
 {
     include_once dirname(dirname(__DIR__)) . '/helpers/tests/links.php';
     //include_once(dirname(dirname(__DIR__)) . '/helpers/tests/abstracts.php');
     $auditor = new \Hubzero\Content\Auditor('resource');
     $auditor->registerTest(new \Components\Resources\Helpers\Tests\Links());
     //$auditor->registerTest(new \Components\Resources\Helpers\Tests\Abstracts);
     $test = Request::getVar('test');
     $status = Request::getVar('status', 'failed');
     if (!in_array($status, array('skipped', 'passed', 'failed'))) {
         $status = 'failed';
     }
     $audits = $auditor->getTests();
     if (count($audits) == 1) {
         foreach ($audits as $key => $tester) {
             $test = $key;
         }
         $status = $status ? $status : 'failed';
     }
     $this->view->set('test', $test)->set('status', $status)->set('tests', $auditor->getReport())->setLayout('check')->display();
 }