diff options
author | Silvio <silvio@devlet.com.br> | 2010-11-18 16:07:50 -0200 |
---|---|---|
committer | Silvio <silvio@devlet.com.br> | 2010-11-18 16:07:50 -0200 |
commit | f58eb1685cc0b70e3b09e85c7dfa1d458dfccfc3 (patch) | |
tree | a01af13efd31eb049420f0bd6a24b0f88574ad17 /lib/task/isisBatchTask.class.php | |
parent | 21eb6a370a258312903a1d0d5315861d0cc9200b (diff) | |
download | sf_isis_importer_plugin-f58eb1685cc0b70e3b09e85c7dfa1d458dfccfc3.tar.gz sf_isis_importer_plugin-f58eb1685cc0b70e3b09e85c7dfa1d458dfccfc3.tar.bz2 |
Initial isis:batch task
Diffstat (limited to 'lib/task/isisBatchTask.class.php')
-rw-r--r-- | lib/task/isisBatchTask.class.php | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/lib/task/isisBatchTask.class.php b/lib/task/isisBatchTask.class.php new file mode 100644 index 0000000..95be44c --- /dev/null +++ b/lib/task/isisBatchTask.class.php @@ -0,0 +1,74 @@ +<?php + +class isisBatchTask extends mySfTask +{ + protected function configure() + { + $this->addArgument('rows', sfCommandArgument::OPTIONAL, 'Number of rows to process for each task'); + $this->addOptions(array( + new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name'), + new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), + new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'), + new sfCommandOption('loglevel', 'l', sfCommandOption::PARAMETER_REQUIRED, 'Log level', 'info'), + new sfCommandOption('database', 'd', sfCommandOption::PARAMETER_REQUIRED, 'Database', null), + )); + + $this->namespace = 'isis'; + $this->name = 'batch'; + $this->briefDescription = 'Imports an ISIS database into the application, batch version'; + $this->detailedDescription = <<<EOF +The [isis:import|INFO] task imports an ISIS database into the application. +This is the batch version and uses PNCTL to avoid memory exhaustion. +Call it with: + + [php symfony isis:batch|INFO] +EOF; + } + + protected function execute($arguments = array(), $options = array()) + { + // initialize the database connection + $databaseManager = new sfDatabaseManager($this->configuration); + $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); + + // Initialize an IsisConnector. + $class = (class_exists('IsisImporterManager')) ? 'IsisImporterManager' : 'sfIsisImporterManager'; + $isis = new $class($options['loglevel']); + + // Error handling. + if ($isis == FALSE) + { + $this->logSection('isis', 'Error opening ISIS database.'); + return FALSE; + } + + $databases = $isis->databases($options['database']); + + foreach ($databases as $database) + { + $rows = (isset($arguments['rows'])) ? $argument['rows'] : 20; + $max = 1000; // TODO + + for ($offset = 0; $offset <= $max; $offset = $offset + $rows) + { + $pid = pcntl_fork(); + if ($pid == -1) + { + die('Could not fork'); + } + else if ($pid) + { + // We are the parent. + // Protect against Zombie children. + pcntl_wait($status); + } + else + { + // We are the child. + // Mass ISIS import. + $isis->massImport($this, 'task', $rows, $offset, $database); + } + } + } + } +} |