Commit 0cbecd3e authored by Baudouin Feildel's avatar Baudouin Feildel
Browse files

Add preCheck and getLogger to AbstractImporter

parent 9ad7994d
......@@ -4,6 +4,8 @@ namespace App\Service\Importer;
use http\Exception\InvalidArgumentException;
use Psr\Log\LoggerInterface;
use RuntimeException;
use SplFileObject;
use Symfony\Component\HttpFoundation\File\File;
abstract class AbstractImporter
......@@ -41,11 +43,15 @@ abstract class AbstractImporter
public function __construct($childClassInstance, LoggerInterface $logger) {
if (!($childClassInstance instanceof UserImporter) &&
!($childClassInstance instanceof GroupImporter))
throw new \RuntimeException("Only UserImporter, GroupImporter, UserPermImporter and GroupPermImporter can extend AbstractImporter");
throw new RuntimeException("Only UserImporter, GroupImporter, UserPermImporter and GroupPermImporter can extend AbstractImporter");
$this->logger = $logger;
}
protected function getLogger() : LoggerInterface {
return $this->logger;
}
/**
* @return File
*/
......@@ -121,14 +127,17 @@ abstract class AbstractImporter
'dry' => $this->dry
]);
$this->preCheck();
$f = $this->file->openFile();
$f->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY | \SplFileObject::DROP_NEW_LINE);
$f->setFlags(SplFileObject::READ_CSV | SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE);
$f->setCsvControl($this->csvDelimiter, "\"", "\\");
$i = 0;
// Disable any time limit on PHP Script
// Apache or other HTTP servers may have a timeout
// This should be handled asynchronously
set_time_limit(0);
if($this->strategy->replace())
......@@ -146,6 +155,14 @@ abstract class AbstractImporter
}
}
/**
* Run checks before processing the file
* @throws ImportException
*/
protected function preCheck(): void {
// Deliberately empty
}
/**
* Clear repository before import (used with Replace strategy)
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment