Skip to content

Commit

Permalink
Release 3.3.1c (#989)
Browse files Browse the repository at this point in the history
* feat : add parameter to change the number of result of the rule list view

* Connector : File adapted to Myddleware3
* Connector : Database, fix error handling row (#986)
* Connector : Moodle manage custom fields for users and courses (#987)
  • Loading branch information
Myddleware authored Mar 27, 2023
1 parent 310a9e8 commit 3aa3c2b
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MYDDLEWARE_VERSION=3.3.1b
MYDDLEWARE_VERSION=3.3.1c

APP_SECRET=Thissecretisnotsosecretchangeit
APP_ENV=prod
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,14 @@ public function ruleListAction(int $page = 1)

$this->getInstanceBdd();
$compact['nb'] = 0;

$pager = $this->tools->getParamValue('ruleListPager');
$compact = $this->nav_pagination([
'adapter_em_repository' => $this->entityManager->getRepository(Rule::class)->findListRuleByUser($this->getUser()),
'maxPerPage' => isset($this->params['pager']) ? $this->params['pager'] : 20,
'maxPerPage' => isset($pager) ? $pager : 20,
'page' => $page,
]);


// Si tout se passe bien dans la pagination
if ($compact) {
// Si aucune règle
Expand Down
15 changes: 15 additions & 0 deletions src/Manager/ToolsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@ public function getPhpVersion()

return $php;
}


public function getParamValue($paramName)
{
// Get the custom php version first
$select = "SELECT * FROM config WHERE name = :param_name";
$stmt = $this->connection->prepare($select);
$stmt->bindValue(':param_name', $paramName);
$result = $stmt->executeQuery();
$config = $result->fetchAssociative();
if (!empty($config['value'])) {
return $config['value'];
}
return null;
}
}

class ToolsManager extends toolscore
Expand Down
16 changes: 14 additions & 2 deletions src/Solutions/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ public function readData($param)
*/
protected function create($param, $record, $idDoc = null)
{

// Get the target reference field
if (!isset($param['ruleParams']['targetFieldId'])) {
throw new Exception('targetFieldId has to be specified for the data creation.');
Expand Down Expand Up @@ -423,13 +424,19 @@ protected function create($param, $record, $idDoc = null)
throw new Exception('Create: '.$errorInfo[2].' . Query : '.$sql);
}

// Check if the row has been created
if ($q->rowCount() === 0) {
throw new Exception('No row was created for the id : ' . $idTarget);
}

// If the target reference field isn't in data sent
if (!isset($idTarget)) {
// If the target reference field is a primary key auto increment, we retrive the value here
$idTarget = $this->pdo->lastInsertId();
}

return $idTarget;

}

/**
Expand Down Expand Up @@ -464,8 +471,8 @@ protected function update($param, $record, $idDoc = null)
throw new Exception('Update: '.$errorInfo[2].' . Query : '.$sql);
}
// No modification
if (0 == $q->rowCount()) {
$this->message = 'There is no error but the query hasn\'t modified any record.';
if ($q->rowCount() === 0) {
throw new Exception('No row was updated for the id : ' . $record['target_id']);
}
// Several modifications
if (
Expand Down Expand Up @@ -502,6 +509,11 @@ public function delete($param, $record)
throw new Exception('Delete: '.$errorInfo[2].' . Query : '.$sql);
}

// No deletion
if ($q->rowCount() === 0) {
throw new Exception('No row was deleted for the id : ' . $record['target_id']);
}

return $record['target_id'];
}

Expand Down
23 changes: 11 additions & 12 deletions src/Solutions/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class filecore extends solution
protected $baseUrl;
protected array $messages = [];
protected array $duplicateDoc = [];
protected \Doctrine\DBAL\Connection $connection;
protected $sshconnection;
protected string $delimiter = ';';
protected string $enclosure = '"';
protected string $escape = '';
Expand All @@ -60,14 +60,14 @@ public function login($paramConnexion): void
throw new \Exception('Please enable extension ssh2. Help here : http://php.net/manual/fr/ssh2.installation.php');
}
// Connect to the server
$this->connection = ssh2_connect($this->paramConnexion['host'], $this->paramConnexion['port']);
ssh2_auth_password($this->connection, $this->paramConnexion['login'], $this->paramConnexion['password']);
$this->sshconnection = ssh2_connect($this->paramConnexion['host'], $this->paramConnexion['port']);
ssh2_auth_password($this->sshconnection, $this->paramConnexion['login'], $this->paramConnexion['password']);

// Check if the directory exist
$stream = ssh2_exec($this->connection, 'cd '.$this->paramConnexion['directory'].';pwd');
$stream = ssh2_exec($this->sshconnection, 'cd '.$this->paramConnexion['directory'].';pwd');
stream_set_blocking($stream, true);
$output = stream_get_contents($stream);
if (trim($this->paramConnexion['directory']) != trim($output)) {
if (strpos(trim($output), trim($this->paramConnexion['directory'])) === false) {
throw new \Exception('Failed to access to the directory'.$this->paramConnexion['directory'].'. Could you check if this directory exists and if the user has the right to read it. ');
}

Expand Down Expand Up @@ -115,7 +115,7 @@ public function get_modules($type = 'source'): array
{
try {
// Get the subfolders of the current directory
$stream = ssh2_exec($this->connection, 'cd '.$this->paramConnexion['directory'].';ls -d */');
$stream = ssh2_exec($this->sshconnection, 'cd '.$this->paramConnexion['directory'].';ls -d */');
stream_set_blocking($stream, true);
$output = stream_get_contents($stream);
// Transform the directory list in an array
Expand Down Expand Up @@ -148,7 +148,7 @@ public function get_module_fields($module, $type = 'source', $param = null): arr
$file = $this->get_last_file($this->paramConnexion['directory'].'/'.$module, '1970-01-01 00:00:00');
$fileName = trim($this->paramConnexion['directory'].'/'.$module.$file);
// Open the file
$sftp = ssh2_sftp($this->connection);
$sftp = ssh2_sftp($this->sshconnection);
$stream = fopen('ssh2.sftp://'.intval($sftp).$fileName, 'r');
$headerString = trim(fgets($stream));
// Close the file
Expand Down Expand Up @@ -290,9 +290,9 @@ public function readData($param)
}

$fileName = $this->paramConnexion['directory'].'/'.$param['module'].$file;

// Open the file
$sftp = ssh2_sftp($this->connection);
$sftp = ssh2_sftp($this->sshconnection);
$stream = fopen('ssh2.sftp://'.intval($sftp).$fileName, 'r');
$header = $this->getFileHeader($stream, $param);

Expand All @@ -303,7 +303,7 @@ public function readData($param)
$allRuleField[] = $param['ruleParams']['fieldId'];

// Get the date of modification of the file
$new_date_ref = ssh2_exec($this->connection, 'cd '.$this->paramConnexion['directory'].'/'.$param['module'].';stat -c %y '.$file);
$new_date_ref = ssh2_exec($this->sshconnection, 'cd '.$this->paramConnexion['directory'].'/'.$param['module'].';stat -c %y '.$file);
stream_set_blocking($new_date_ref, true);
$new_date_ref = stream_get_contents($new_date_ref);
$new_date_ref = trim($new_date_ref);
Expand Down Expand Up @@ -433,7 +433,6 @@ public function readData($param)
if (!empty($stream)) {
fclose($stream);
}

return $result;
}

Expand Down Expand Up @@ -577,7 +576,7 @@ protected function validateRow($row, $idRow, $rowNumber): bool

protected function get_last_file($directory, $date_ref): string
{
$stream = ssh2_exec($this->connection, 'cd '.$directory.';find . -newermt "'.$date_ref.'" -type f | sort | head -n 1');
$stream = ssh2_exec($this->sshconnection, 'cd '.$directory.';find . -newermt "'.$date_ref.'" -type f | sort | head -n 1');
stream_set_blocking($stream, true);
$file = stream_get_contents($stream);
$file = ltrim($file, './'); // The filename can have ./ at the beginning
Expand Down
Loading

0 comments on commit 3aa3c2b

Please sign in to comment.