logger = sfIsisImporterLog::getInstance($loglevel); } /** * Log dispatcher. * * @param string $message Log message * @param string $level Log level */ public function log($message, $level = 'info') { $this->logger->log($message, $level); } /** * Progress notifier dispatcher. * * @param int $entry Entry number */ public function progress($entry) { $this->processed = $this->logger->progress($entry, $this->entries); } /** * Create an ISIS configuration for a given database. * * @param string $database Database name * @return array Basic configuration */ public function config($database) { // Default cinisis config file. $config = $this->isis->file(); if (file_exists($config)) { $this->log("Using Cinisis config file $config."); $config = sfYaml::load($config); } else { // Default configuration. $this->log("Cinisis config file not found, building configuration."); $config = array( 'implementation' => 'BiblioIsis', ); } $config['database'] = $database; return $config; } /** * List available ISIS databases. * * @return array Available databases */ public function databases() { foreach (glob(sfConfig::get('sf_lib_dir') ."/cinisis/schemas/*.yaml") as $file) { $databases[] = basename($file, '.yaml'); } return $databases; } /** * After import procedure. */ public function afterImport() { // Output ISIS log messages. if (is_array($this->isis->db->log)) { foreach ($this->isis->db->log as $log) { $this->log("[isis] $log"); } } $this->log("Finished mass import procedure.", 'notice'); $this->log("Total entries processed: $this->processed.", 'notice'); } /** * Execute a mass import of ISIS database entries. This function reads * each database entry and dispatch each field read to a custom * dispatch function. * * @param object $caller Caller object * @param string $section Caller section (whether an action or task) * @param int $entries Number of entries to import (defaults to all) */ public function massImport($caller, $section, $entries = NULL) { // Additional logging settings. $this->logger->setCaller($caller); $this->logger->setSection($section); foreach ($this->databases() as $database) { // Open database. $importer = $this->newImporter($database); if ($importer) { // Determine base model and max entries. $this->log('Starting mass import procedure for config '. $database .'.', 'notice'); $base_model = $importer->format['db']['base_model']; $this->entries = ($entries != NULL && $entries <= $importer->entries) ? $entries : $importer->entries; if ($base_model) { for ($entry = 1; $entry <= $this->entries; $entry++) { $importer->addEntry($base_model, $entry); $this->progress($entry); } } $this->afterImport(); } } } /** * Setup a new importer. * * @param string $database Database name * @return mixed Importer object or false */ public function newImporter($database) { $class = 'IsisImporter'. ucfirst($database); if (class_exists($class)) { return new $class($this->config($database)); } return false; } }