diff --git a/plugin/migrationmoodle/admin.php b/plugin/migrationmoodle/admin.php index 43901b58b1..dcc741c6ff 100644 --- a/plugin/migrationmoodle/admin.php +++ b/plugin/migrationmoodle/admin.php @@ -1,7 +1,7 @@ get_lang($taskName) ); - echo '
';
$taskName = 'Chamilo\\PluginBundle\\MigrationMoodle\\Task\\'.$taskName;
/** @var BaseTask $task */
$task = new $taskName();
- try {
- $task->execute();
- } catch (MigrationMoodleException $exception) {
- $exception->displayAsString();
- } catch (Exception $exception) {
- echo $exception->getTraceAsString();
- }
-
+ echo '';
+ $task->execute();
echo '';
}
diff --git a/plugin/migrationmoodle/src/Exceptions/Exception.php b/plugin/migrationmoodle/src/Exceptions/Exception.php
deleted file mode 100644
index da83ab2335..0000000000
--- a/plugin/migrationmoodle/src/Exceptions/Exception.php
+++ /dev/null
@@ -1,23 +0,0 @@
-getMessage()];
-
- if ($this->getPrevious()) {
- $pieces[] = "\t".$this->getPrevious()->getMessage();
- }
-
- echo implode(PHP_EOL, $pieces);
- }
-}
diff --git a/plugin/migrationmoodle/src/Exceptions/ExtractException.php b/plugin/migrationmoodle/src/Messages/ExtractMessage.php
similarity index 54%
rename from plugin/migrationmoodle/src/Exceptions/ExtractException.php
rename to plugin/migrationmoodle/src/Messages/ExtractMessage.php
index 79731cf6a2..6d9a9c3649 100644
--- a/plugin/migrationmoodle/src/Exceptions/ExtractException.php
+++ b/plugin/migrationmoodle/src/Messages/ExtractMessage.php
@@ -1,19 +1,19 @@
incomingData = $incomingData;
- parent::__construct($message, 0, $previous);
+ parent::__construct($message, $previous);
}
public function displayAsString()
diff --git a/plugin/migrationmoodle/src/Messages/Message.php b/plugin/migrationmoodle/src/Messages/Message.php
new file mode 100644
index 0000000000..9946246d19
--- /dev/null
+++ b/plugin/migrationmoodle/src/Messages/Message.php
@@ -0,0 +1,64 @@
+message = $message;
+ $this->previous = $previous;
+
+ $this->displayAsString();
+ }
+
+ /**
+ * @return string
+ */
+ public function getMessage()
+ {
+ return $this->message;
+ }
+
+ /**
+ * @return Throwable
+ */
+ public function getPrevious()
+ {
+ return $this->previous;
+ }
+
+ public function displayAsString()
+ {
+ $pieces = [$this->message];
+
+ if ($this->previous) {
+ $pieces[] = "\t".$this->previous->getMessage();
+ }
+
+ echo implode(PHP_EOL, $pieces);
+ }
+}
diff --git a/plugin/migrationmoodle/src/Exceptions/TransformException.php b/plugin/migrationmoodle/src/Messages/TransformMessage.php
similarity index 70%
rename from plugin/migrationmoodle/src/Exceptions/TransformException.php
rename to plugin/migrationmoodle/src/Messages/TransformMessage.php
index 325b6085ee..f06d0e02ce 100644
--- a/plugin/migrationmoodle/src/Exceptions/TransformException.php
+++ b/plugin/migrationmoodle/src/Messages/TransformMessage.php
@@ -1,16 +1,16 @@
extractedData = $extractedData;
- parent::__construct($message, 0, $previous);
+ parent::__construct($message, $previous);
}
public function displayAsString()
diff --git a/plugin/migrationmoodle/src/Task/BaseTask.php b/plugin/migrationmoodle/src/Task/BaseTask.php
index 97875e4c68..5a72aaac74 100644
--- a/plugin/migrationmoodle/src/Task/BaseTask.php
+++ b/plugin/migrationmoodle/src/Task/BaseTask.php
@@ -3,13 +3,12 @@
namespace Chamilo\PluginBundle\MigrationMoodle\Task;
-use Chamilo\PluginBundle\MigrationMoodle\Exceptions\Exception;
-use Chamilo\PluginBundle\MigrationMoodle\Exceptions\ExtractException;
-use Chamilo\PluginBundle\MigrationMoodle\Exceptions\LoadException;
-use Chamilo\PluginBundle\MigrationMoodle\Exceptions\TransformException;
use Chamilo\PluginBundle\MigrationMoodle\Interfaces\ExtractorInterface;
use Chamilo\PluginBundle\MigrationMoodle\Interfaces\LoaderInterface;
use Chamilo\PluginBundle\MigrationMoodle\Interfaces\TransformerInterface;
+use Chamilo\PluginBundle\MigrationMoodle\Messages\ExtractMessage;
+use Chamilo\PluginBundle\MigrationMoodle\Messages\LoadMessage;
+use Chamilo\PluginBundle\MigrationMoodle\Messages\TransformMessage;
use Chamilo\PluginBundle\MigrationMoodle\Traits\MapTrait\MapTrait;
/**
@@ -67,27 +66,33 @@ abstract class BaseTask
*/
abstract public function getLoadConfiguration();
- /**
- * @throws Exception
- */
public function execute()
{
foreach ($this->extractFiltered() as $extractedData) {
try {
$incomingData = $this->transformer->transform($extractedData);
} catch (\Exception $exception) {
- throw new TransformException($extractedData, $exception);
+ new TransformMessage($extractedData, $exception);
+
+ continue;
}
try {
$loadedId = $this->loader->load($incomingData);
} catch (\Exception $exception) {
- throw new LoadException($incomingData, $exception);
+ new LoadMessage($incomingData, $exception);
+
+ continue;
}
- $hash = $this->saveMapLog($extractedData['id'], $loadedId);
+ try {
+ $hash = $this->saveMapLog($extractedData['id'], $loadedId);
- echo "Data migrated. $hash".PHP_EOL;
+ echo "Data migrated. $hash".PHP_EOL;
+ } catch (\Exception $exception) {
+ echo "Data migrated, but... \n";
+ echo "\n".$exception->getTraceAsString();
+ }
}
}
@@ -111,8 +116,6 @@ abstract class BaseTask
}
/**
- * @throws ExtractException
- *
* @return \Generator
*/
private function extractFiltered()
@@ -126,7 +129,7 @@ abstract class BaseTask
yield $extractedData;
}
} catch (\Exception $exception) {
- throw new ExtractException($exception);
+ new ExtractMessage($exception);
}
}