コード例 #1
0
 /**
  * Constructor
  *
  * @param boolean $console Specify whether RecordManager is executed on the
  * console so that log output is also output to the console.
  * @param boolean $verbose Whether verbose output is enabled
  */
 public function __construct($console = false, $verbose = false)
 {
     global $configArray;
     global $logger;
     date_default_timezone_set($configArray['Site']['timezone']);
     $this->log = new Logger();
     if ($console) {
         $this->log->logToConsole = true;
     }
     $this->verbose = $verbose;
     // Store logger in a global so that others can access it easily
     $logger = $this->log;
     if (isset($configArray['Mongo']['counts']) && $configArray['Mongo']['counts']) {
         $this->counts = true;
     }
     if (isset($configArray['Mongo']['compressed_records']) && !$configArray['Mongo']['compressed_records']) {
         $this->compressedRecords = false;
     }
     $basePath = substr(__FILE__, 0, strrpos(__FILE__, DIRECTORY_SEPARATOR));
     $basePath = substr($basePath, 0, strrpos($basePath, DIRECTORY_SEPARATOR));
     $this->dataSourceSettings = $configArray['dataSourceSettings'] = parse_ini_file("{$basePath}/conf/datasources.ini", true);
     $this->basePath = $basePath;
     try {
         $timeout = isset($configArray['Mongo']['connect_timeout']) ? $configArray['Mongo']['connect_timeout'] : 300000;
         $mongo = new MongoClient($configArray['Mongo']['url'], ['connectTimeoutMS' => $timeout]);
         $this->db = $mongo->selectDB($configArray['Mongo']['database']);
         $this->cursorTimeout = isset($configArray['Mongo']['cursor_timeout']) ? $configArray['Mongo']['cursor_timeout'] : 300000;
     } catch (Exception $e) {
         $this->log->log('startup', 'Failed to connect to MongoDB: ' . $e->getMessage(), Logger::FATAL);
         throw $e;
     }
     // Used for format mapping in dedup handler
     $solrUpdater = new SolrUpdater($this->db, $this->basePath, $this->log, $this->verbose, $this->cursorTimeout);
     $dedupClass = isset($configArray['Site']['dedup_handler']) ? $configArray['Site']['dedup_handler'] : 'DedupHandler';
     include_once "{$dedupClass}.php";
     $this->dedupHandler = new $dedupClass($this->db, $this->log, $this->verbose, $solrUpdater, $this->cursorTimeout);
     if (isset($configArray['Site']['full_title_prefixes'])) {
         MetadataUtils::$fullTitlePrefixes = array_map(['MetadataUtils', 'normalize'], file("{$basePath}/conf/{$configArray['Site']['full_title_prefixes']}", FILE_IGNORE_NEW_LINES));
     }
     // Read the abbreviations file
     MetadataUtils::$abbreviations = isset($configArray['Site']['abbreviations']) ? $this->readListFile($configArray['Site']['abbreviations']) : [];
     // Read the artices file
     MetadataUtils::$articles = isset($configArray['Site']['articles']) ? $this->readListFile($configArray['Site']['articles']) : [];
 }