Commit 24225775 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Amélioration de RunSQLProcess : petite désadhérance avec Oracle, nouveaux...

Amélioration de RunSQLProcess : petite désadhérance avec Oracle, nouveaux attributs dans RunSQLResult, correction d'un warning
parent 07baff74
Pipeline #12334 passed with stage
in 18 seconds
......@@ -6,6 +6,10 @@ CHANGELOG
- Migration vers Bootstrap 5 (front-end).
4.0.3
-----
- Amélioration du RunSQLProcess : petite désadhérance avec Oracle, nouveaux attributs dans RunSQLResult, correction d'un warning.
4.0.2 (15/12/2021)
------------------
- [FIX] uploader cassé : FormElementManagerV3Polyfill est deprecated et inutilisé, remplacé par FormElementManager
......
......@@ -68,7 +68,10 @@ abstract class ProcessResult implements ProcessResultInterface
public function __destruct()
{
fclose($this->logStream);
// Test ajouté pour éviter l'étrange "Warning: fclose(): supplied resource is not a valid stream resource"
if (is_resource($this->logStream)) {
fclose($this->logStream);
}
}
/**
......
......@@ -4,15 +4,15 @@ namespace UnicaenApp\Service\SQL;
use Doctrine\DBAL\Connection;
use Exception;
use UnicaenApp\Exception\RuntimeException;
use Laminas\Log\LoggerAwareTrait;
use Laminas\Stdlib\Glob;
use UnicaenApp\Exception\RuntimeException;
class RunSQLProcess
{
use LoggerAwareTrait;
const QUERIES_SPLIT_PATTERN = "#^/$#m";
const QUERIES_SPLIT_PATTERN = "#^/$#m"; // oracle !!
const LOG_FILE_EXT = '.log.sql';
const LOG_FILE_EXT_PATTERN = '.log.*.sql';
const LOG_FILE_EXT_TEMPLATE = '.log.%d.sql';
......@@ -32,6 +32,11 @@ class RunSQLProcess
*/
private $connection;
/**
* @var string
*/
private $queriesSplitPattern = self::QUERIES_SPLIT_PATTERN;
/**
* @var string[]
*/
......@@ -75,6 +80,17 @@ class RunSQLProcess
return $this;
}
/**
* @param string $queriesSplitPattern
* @return self
*/
public function setQueriesSplitPattern($queriesSplitPattern)
{
$this->queriesSplitPattern = $queriesSplitPattern;
return $this;
}
/**
* Exécute dans la transaction courante toutes les instructions d'un script SQL.
*
......@@ -126,7 +142,7 @@ class RunSQLProcess
*/
protected function extractQueriesFromScript()
{
$parts = preg_split(self::QUERIES_SPLIT_PATTERN, file_get_contents($this->scriptPath));
$parts = preg_split($this->queriesSplitPattern, file_get_contents($this->scriptPath));
$queries = array_filter(array_map('trim', $parts));
if (count($queries) === 0) {
......@@ -144,6 +160,8 @@ class RunSQLProcess
private function executeQueries()
{
$result = new RunSQLResult();
$result->setScriptPath($this->scriptPath);
$result->setLogFilePath($this->logFilePath);
$result->attachLogger($this->logger);
$result->setIsSuccess(true);
......
......@@ -11,5 +11,49 @@ use UnicaenApp\Process\ProcessResult;
*/
class RunSQLResult extends ProcessResult
{
/**
* @var string
*/
protected $scriptPath;
/**
* @var string
*/
protected $logFilePath;
/**
* @return string
*/
public function getScriptPath()
{
return $this->scriptPath;
}
/**
* @param string $scriptPath
* @return self
*/
public function setScriptPath($scriptPath)
{
$this->scriptPath = $scriptPath;
return $this;
}
/**
* @return string
*/
public function getLogFilePath()
{
return $this->logFilePath;
}
/**
* @param string $logFilePath
* @return self
*/
public function setLogFilePath($logFilePath)
{
$this->logFilePath = $logFilePath;
return $this;
}
}
\ No newline at end of file
Supports Markdown
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