Ejemplo n.º 1
0
 /**
  * Get the last and next run times for the scheduler.
  * @return bool true if scheduler is overdue
  */
 function checkOverDue()
 {
     $this->aTimes = schedulerUtil::checkLastRunTime();
     $sNextRunTime = $this->aTimes['nextruntime'];
     $iNow = time();
     $iNext = strtotime($sNextRunTime);
     if ($iNow > $iNext) {
         $iDif = $iNow - $iNext;
         // if it hasn't run for a whole day and its not a fresh install then display dashlet alert.
         if ($iDif > 60 * 60 * 24) {
             // check if its a new install
             $check = schedulerUtil::checkNewInstall();
             return !$check;
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 public function migrateDocuments($max = null)
 {
     global $default;
     $default->log->info(_kt('migrateDocuments: starting'));
     if (!$this->doesDiagnosticsPass(true)) {
         $default->log->info(_kt('migrateDocuments: stopping - diagnostics problem. The dashboard will provide more information.'));
         return;
     }
     if (KTUtil::getSystemSetting('migrationComplete') == 'true') {
         $default->log->info(_kt('migrateDocuments: stopping - migration is complete.'));
         return;
     }
     $config =& KTConfig::getSingleton();
     if (is_null($max)) {
         $max = $config->get('indexer/batchMigrateDocument', 500);
     }
     $lockFile = $config->get('cache/cacheDirectory') . '/migration.lock';
     if (is_file($lockFile)) {
         $default->log->info(_kt('migrateDocuments: stopping - migration lockfile detected.'));
         return;
     }
     touch($lockFile);
     $startTime = KTUtil::getSystemSetting('migrationStarted');
     if (is_null($startTime)) {
         KTUtil::setSystemSetting('migrationStarted', time());
     }
     $maxLoops = 5;
     $max = ceil($max / $maxLoops);
     $start = KTUtil::getBenchmarkTime();
     $noDocs = false;
     $numDocs = 0;
     for ($loop = 0; $loop < $maxLoops; $loop++) {
         $sql = "SELECT\n        \t\t\tdocument_id, document_text\n\t\t\t\tFROM\n\t\t\t\t\tdocument_text\n\t\t\t\tORDER BY document_id\n \t\t\t\t\tLIMIT {$max}";
         $result = DBUtil::getResultArray($sql);
         if (PEAR::isError($result)) {
             $default->log->info(_kt('migrateDocuments: db error'));
             break;
         }
         $docs = count($result);
         if ($docs == 0) {
             $noDocs = true;
             break;
         }
         $numDocs += $docs;
         foreach ($result as $docinfo) {
             $docId = $docinfo['document_id'];
             $document = Document::get($docId);
             if (PEAR::isError($document) || is_null($document)) {
                 $sql = "DELETE FROM document_text WHERE document_id={$docId}";
                 DBUtil::runQuery($sql);
                 $default->log->error(sprintf(_kt('migrateDocuments: Could not get document %d\'s document! Removing content!'), $docId));
                 continue;
             }
             $version = $document->getMajorVersionNumber() . '.' . $document->getMinorVersionNumber();
             $targetFile = tempnam($tempPath, 'ktindexer');
             if (file_put_contents($targetFile, $docinfo['document_text']) === false) {
                 $default->log->error(sprintf(_kt('migrateDocuments: Cannot write to \'%s\' for document id %d'), $targetFile, $docId));
                 continue;
             }
             // free memory asap ;)
             unset($docinfo['document_text']);
             $title = $document->getName();
             $indexStatus = $this->indexDocumentAndDiscussion($docId, $targetFile, $title, $version);
             if ($indexStatus) {
                 $sql = "DELETE FROM document_text WHERE document_id={$docId}";
                 DBUtil::runQuery($sql);
             } else {
                 $default->log->error(sprintf(_kt("migrateDocuments: Problem indexing document %d"), $docId));
             }
             @unlink($targetFile);
         }
     }
     @unlink($lockFile);
     $time = KTUtil::getBenchmarkTime() - $start;
     KTUtil::setSystemSetting('migrationTime', KTUtil::getSystemSetting('migrationTime', 0) + $time);
     KTUtil::setSystemSetting('migratedDocuments', KTUtil::getSystemSetting('migratedDocuments', 0) + $numDocs);
     $default->log->info(sprintf(_kt('migrateDocuments: stopping - done in %d seconds!'), $time));
     if ($noDocs) {
         $default->log->info(_kt('migrateDocuments: Completed!'));
         KTUtil::setSystemSetting('migrationComplete', 'true');
         schedulerUtil::deleteByName('Index Migration');
         $default->log->debug(_kt('migrateDocuments: Disabling \'Index Migration\' task by removing scheduler entry.'));
     }
 }
Ejemplo n.º 3
0
 /**
  * Check if this is a new installation
  *
  */
 function checkNewInstall()
 {
     // The date and time of installation is not stored anywhere so we work around it
     // On installation the run_time of all tasks is set to '2007-10-01', so we check if all the tasks have the same run_time date with time set to 00:00:00
     // We then set run_time to the current date, ensuring the time is not 00.
     $query = 'SELECT count(*) as cnt, run_time FROM scheduler_tasks s GROUP BY run_time';
     $res = DBUtil::getResultArray($query);
     if (PEAR::isError($res)) {
         return false;
     }
     // if they aren't all the same return false - not a fresh install
     $iCnt = count($res);
     if ($iCnt > 1) {
         return false;
     }
     // Check if the time is 00
     $sRunTime = $res[0]['run_time'];
     $aRunTime = explode(' ', $sRunTime);
     if (!isset($aRunTime[1]) || empty($aRunTime[1])) {
         // set install date
         schedulerUtil::setInstallDate();
         return true;
     }
     if ($aRunTime[1] == '00:00:00') {
         // set install date
         schedulerUtil::setInstallDate();
         return true;
     }
     return false;
 }
Ejemplo n.º 4
0
 /**
  * Toggle the enable/disable on the task
  */
 function do_updateStatus()
 {
     $fId = schedulerUtil::arrayGet($_REQUEST, 'fId');
     schedulerUtil::toggleStatus($fId);
 }
Ejemplo n.º 5
0
 /**
  * Register the task in the scheduler
  */
 function registerTask()
 {
     schedulerUtil::registerTask($this->sName, $this->sPath, $this->aParams, $this->sFreq, $this->iStartTime, $this->sStatus);
 }