Example #1
0
 /**
  * Verify links to records
  *
  * @param string[] $recordIdArray Array of record IDs
  *
  * @return boolean True if any links were fixed
  * @access public
  */
 public function verifyLinks($recordIdArray)
 {
     $fixed = false;
     include_once 'services/MyResearch/lib/Comments_record.php';
     // Remove any orphaned links
     $commentsRecord = new Comments_record();
     $commentsRecord->comment_id = $this->id;
     if ($commentsRecord->find()) {
         while ($commentsRecord->fetch()) {
             if (!in_array($commentsRecord->record_id, $recordIdArray)) {
                 $commentsRecord->delete();
                 $fixed = true;
             }
         }
     }
     // Add missing links
     foreach ($recordIdArray as $recordId) {
         $commentsRecord = new Comments_record();
         $commentsRecord->record_id = $recordId;
         $commentsRecord->comment_id = $this->id;
         if (!$commentsRecord->find()) {
             $commentsRecord->insert();
             $fixed = true;
         }
     }
     return $fixed;
 }
// Setup time zone
date_default_timezone_set($configArray['Site']['timezone']);
// Setup Local Database Connection
ConnectionManager::connectToDatabase();
// Setup index connection
ConnectionManager::connectToIndex();
// Delete the expired searches -- this cleans up any junk left in the database
// from old search histories that were not caught by the session garbage collector.
$count = 0;
$fixed = 0;
$searchObject = SearchObjectFactory::initSearchObject();
$searchObject->disableLogging();
$comments = new Comments();
if ($comments->find()) {
    while ($comments->fetch()) {
        $commentsRecord = new Comments_record();
        $commentsRecord->comment_id = $comments->id;
        if ($commentsRecord->find(true)) {
            $query = 'local_ids_str_mv:"' . addcslashes($commentsRecord->record_id, '"') . '"';
            $searchObject->setQueryString($query);
            $result = $searchObject->processSearch();
            $searchObject->close();
            if (PEAR::isError($result)) {
                PEAR::raiseError($result->getMessage());
            }
            if ($result['response']['numFound'] > 0) {
                $idArray = $result['response']['docs'][0]["local_ids_str_mv"];
                if ($comments->verifyLinks($idArray)) {
                    ++$fixed;
                }
            }