MigrationMoodle: Output buffering - refs BT#15992

pull/3127/head
Angel Fernando Quiroz Campos 6 years ago
parent d380f1ae8f
commit 44a2d778b2
  1. 3
      plugin/migrationmoodle/admin.php
  2. 94
      plugin/migrationmoodle/src/Task/BaseTask.php

@ -6,6 +6,9 @@ use Chamilo\PluginBundle\MigrationMoodle\Task\BaseTask;
$cidReset = true;
ini_set('memory_limit', -1);
ini_set('max_execution_time', 0);
require_once __DIR__.'/../../main/inc/global.inc.php';
api_protect_admin_script(true);

@ -54,8 +54,6 @@ abstract class BaseTask
$this->loader = $this->getLoader();
$this->calledClass = get_called_class();
$this->initMapLog();
}
/**
@ -74,6 +72,42 @@ abstract class BaseTask
abstract public function getLoadConfiguration();
public function execute()
{
$taskId = \Database::insert(
'plugin_migrationmoodle_task',
['name' => $this->getTaskName()]
);
$i = 0;
foreach ($this->executeETL() as $hash => $ids) {
\Database::insert(
'plugin_migrationmoodle_item',
[
'hash' => $hash,
'extracted_id' => (int) $ids['extracted'],
'loaded_id' => (int) $ids['loaded'],
'task_id' => $taskId,
]
);
echo "Data migrated: $hash".PHP_EOL;
$i++;
if ($i % 10 === 0) {
flush();
ob_flush();
}
}
ob_end_flush();
}
/**
* @return \Generator
*/
private function executeETL()
{
foreach ($this->extractFiltered() as $extractedData) {
try {
@ -92,36 +126,13 @@ abstract class BaseTask
continue;
}
try {
$hash = $this->saveMapLog($extractedData['id'], $loadedId);
echo "Data migrated. $hash".PHP_EOL;
} catch (\Exception $exception) {
echo "Data migrated, but... \n";
echo "\n".$exception->getTraceAsString();
}
yield md5("{$extractedData['id']}@@$loadedId") => [
'extracted' => $extractedData['id'],
'loaded' => $loadedId
];
}
}
/**
* @throws \Exception
*/
private function initMapLog()
{
$taskName = $this->getTaskName();
$id = \Database::insert(
'plugin_migrationmoodle_task',
['name' => $taskName]
);
if (empty($id)) {
throw new \Exception("Failed to save task ($taskName).");
}
$this->taskId = $id;
}
/**
* @return \Generator
*/
@ -140,31 +151,6 @@ abstract class BaseTask
}
}
/**
* @param int $extractedId
* @param int $loadedId
*
* @throws \Exception
*
* @return string
*/
private function saveMapLog($extractedId, $loadedId)
{
$hash = md5("$extractedId@@$loadedId");
\Database::insert(
'plugin_migrationmoodle_item',
[
'hash' => $hash,
'extracted_id' => $extractedId,
'loaded_id' => $loadedId,
'task_id' => $this->taskId,
]
);
return $hash;
}
/**
* @return ExtractorInterface
*/

Loading…
Cancel
Save