Author: sevein
Date: Fri Aug 12 14:21:25 2011
New Revision: 9483
Log:
Cosmetic changes
Modified:
trunk/lib/task/importBulkTask.class.php
Modified: trunk/lib/task/importBulkTask.class.php
==============================================================================
--- trunk/lib/task/importBulkTask.class.php Fri Aug 12 11:30:13 2011
(r9482)
+++ trunk/lib/task/importBulkTask.class.php Fri Aug 12 14:21:25 2011
(r9483)
@@ -43,107 +43,136 @@
protected function execute($arguments = array(), $options = array())
{
- $timer = new QubitTimer; // overall timing
+ $timer = new QubitTimer; // overall timing
- $context = sfContext::createInstance($this->configuration);
+ $context = sfContext::createInstance($this->configuration);
- if (empty($arguments['folder']) || !file_exists($arguments['folder'])) {
- throw new sfException('You must specify a valid import folder or
file');
- }
-
- // set indexing preference
- if ($options['noindex']) {
- QubitSearch::getInstance()->disabled = true;
- } else {
- QubitSearch::getInstance()->getEngine()->enableBatchMode();
- }
-
- if (is_dir($arguments['folder'])) {
- // recurse into the import folder
- $files = $this->dir_tree(rtrim($arguments['folder'], '/'));
- } else {
- $files = array($arguments['folder']);
- }
-
- // TODO: add some colour
- $this->log("Importing ".count($files)." files from
".$arguments['folder']." (indexing is ".($options['noindex'] ? "DISABLED" :
"ENABLED").") ...\n");
-
- $count = 0;
- $total = count($files);
- foreach ($files as $file) {
- $start = microtime(true);
-
- // choose import type based on file extension, eg. csv, xml
- if ('csv' == pathinfo($file, PATHINFO_EXTENSION)) {
- $importer = new QubitCsvImport;
- $importer->import($file);
-
- } elseif ('xml' == pathinfo($file, PATHINFO_EXTENSION)) {
- $importer = new QubitXmlImport;
- $importer->import($file, array('strictXmlParsing' => false));
-
- } else {
- // move on to the next file
- continue;
- }
- // try to free up memory
- unset($importer);
+ if (empty($arguments['folder']) || !file_exists($arguments['folder']))
+ {
+ throw new sfException('You must specify a valid import folder or file');
+ }
+
+ // Set indexing preference
+ if ($options['noindex'])
+ {
+ QubitSearch::getInstance()->disabled = true;
+ }
+ else
+ {
+ QubitSearch::getInstance()->getEngine()->enableBatchMode();
+ }
+
+ if (is_dir($arguments['folder']))
+ {
+ // Recurse into the import folder
+ $files = $this->dir_tree(rtrim($arguments['folder'], '/'));
+ }
+ else
+ {
+ $files = array($arguments['folder']);
+ }
+
+ // TODO: Add some colour
+ $this->log("Importing ".count($files)." files from
".$arguments['folder']." (indexing is ".($options['noindex'] ? "DISABLED" :
"ENABLED").") ...\n");
+
+ $count = 0;
+ $total = count($files);
+
+ foreach ($files as $file)
+ {
+ $start = microtime(true);
+
+ // Choose import type based on file extension, eg. csv, xml
+ if ('csv' == pathinfo($file, PATHINFO_EXTENSION))
+ {
+ $importer = new QubitCsvImport;
+ $importer->import($file);
+ }
+ elseif ('xml' == pathinfo($file, PATHINFO_EXTENSION))
+ {
+ $importer = new QubitXmlImport;
+ $importer->import($file, array('strictXmlParsing' => false));
+ }
+ else
+ {
+ // Move on to the next file
+ continue;
+ }
+
+ // Try to free up memory
+ unset($importer);
+
+ $count++;
+ $split = microtime(true) - $start;
+
+ // Store details if output is specified
+ if ($options['output'])
+ {
+ $rows[] = array($count, $split, memory_get_usage());
+ }
+
+ if ($options['v'])
+ {
+ $this->log(basename($file)." imported (".round($split, 2)." s)
(".$count."/".$total.")");
+ }
+ }
+
+ // Create/open output file if specified
+ if ($options['output'])
+ {
+ $fh = fopen($options['output'], 'w+');
+ foreach ($rows as $row)
+ {
+ fputcsv($fh, $row);
+ }
+
+ fputcsv($fh, array('', $timer->elapsed(), memory_get_peak_usage()));
+ fclose($fh);
+ }
+
+ // Optimize index if enabled
+ if (!$options['noindex'])
+ {
+ QubitSearch::getInstance()->getEngine()->optimize();
+ }
- $count++;
- $split = microtime(true) - $start;
+ $this->log("\nSuccessfully imported ".$count." XML/CSV files in
".$timer->elapsed()." s. ".memory_get_peak_usage()." bytes used.");
+ }
- // store details if output is specified
- if ($options['output']) {
- $rows[] = array($count, $split, memory_get_usage());
- }
+ protected function dir_tree($dir)
+ {
+ $path = '';
+ $stack[] = $dir;
- if ($options['v']) {
- $this->log(basename($file)." imported (".round($split, 2)." s)
(".$count."/".$total.")");
+ while ($stack)
+ {
+ $thisdir = array_pop($stack);
+
+ if ($dircont = scandir($thisdir))
+ {
+ $i = 0;
+
+ while (isset($dircont[$i]))
+ {
+ if ($dircont[$i] !== '.' && $dircont[$i] !== '..' &&
!preg_match('/^\..*/', $dircont[$i]))
+ {
+ $current_file = "{$thisdir}/{$dircont[$i]}";
+
+ if (is_file($current_file))
+ {
+ $path[] = "{$thisdir}/{$dircont[$i]}";
+ }
+ elseif (is_dir($current_file))
+ {
+ $stack[] = $current_file;
+ }
}
- }
- // create/open output file if specified
- if ($options['output']) {
- $fh = fopen($options['output'], 'w+');
- foreach ($rows as $row) {
- fputcsv($fh, $row);
- }
- fputcsv($fh, array('', $timer->elapsed(), memory_get_peak_usage()));
- fclose($fh);
+ $i++;
+ }
}
-
- // optimize index if enabled
- if (!$options['noindex']) {
- QubitSearch::getInstance()->getEngine()->optimize();
- }
-
- $this->log("\nSuccessfully imported ".$count." XML/CSV files in
".$timer->elapsed()." s. ".memory_get_peak_usage()." bytes used.");
- }
+ }
- protected function dir_tree($dir) {
- $path = '';
- $stack[] = $dir;
- while ($stack) {
- $thisdir = array_pop($stack);
- if ($dircont = scandir($thisdir)) {
- $i=0;
- while (isset($dircont[$i])) {
- if ($dircont[$i] !== '.' && $dircont[$i] !== '..'
- // ignore system/hidden files
- && !preg_match('/^\..*/', $dircont[$i])) {
-
- $current_file = "{$thisdir}/{$dircont[$i]}";
- if (is_file($current_file)) {
- $path[] = "{$thisdir}/{$dircont[$i]}";
- } elseif (is_dir($current_file)) {
- $stack[] = $current_file;
- }
- }
- $i++;
- }
- }
- }
- return $path;
+ return $path;
}
-
}
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.