Code quality check improvements

This commit is contained in:
Paolo
2022-08-31 15:48:35 +02:00
parent ed9f6e0c9b
commit 537ce0940c
23 changed files with 347 additions and 269 deletions
+42 -18
View File
@@ -1,7 +1,25 @@
<?php
/**
* Copyright (C) 2022 fhcomplete.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
if (! defined('BASEPATH')) exit('No direct script access allowed');
use \stdClass as stdClass;
/**
* Library to manage core extensions
*/
@@ -181,17 +199,15 @@ class ExtensionsLib
// Select all the version of this extension
$this->_ci->ExtensionsModel->addSelect('extension_id');
$result = $this->_ci->ExtensionsModel->loadWhere(array('name' => $extensionName));
if (hasData($result)) // if something was found
// If something was found
if (hasData($result))
{
$extsArray = array();
foreach ($result->retval as $key => $extension) // loops on them
// Loops on them
foreach ($result->retval as $extension)
{
// Remove them all
$result = $this->_ci->ExtensionsModel->delete($extension->extension_id);
if (isSuccess($result))
{
$delExtension = true;
}
if (isSuccess($result)) $delExtension = true;
}
}
}
@@ -432,7 +448,11 @@ class ExtensionsLib
// If no errors occurred
if ($extensionJson != null)
{
// Default value
$fhcomplete_version = 0;
require_once('version.php'); // get the core version
// Checks if the required core version of the extension is the same of this system
if (isset($extensionJson->core_version) && $extensionJson->core_version == $fhcomplete_version)
{
@@ -587,18 +607,22 @@ class ExtensionsLib
for ($sqlDir = $startVersion; $sqlDir <= $extensionJson->version; $sqlDir++)
{
// If a directory with the same value of the version is present in the sql scripts directory
if (($files = glob($pkgSQLsPath.'/'.$sqlDir.'/*'.ExtensionsLib::SQL_FILE_EXTENSION)) != false)
{
$files = glob($pkgSQLsPath.'/'.$sqlDir.'/*'.ExtensionsLib::SQL_FILE_EXTENSION);
if ($files != false)
{
// Loads every sql files
foreach ($files as $file)
{
$sql = file_get_contents($file); // gets the entire content of the file
foreach ($files as $file)
{
$sql = file_get_contents($file); // gets the entire content of the file
$this->_printMessage('Executing query:');
$this->_printMessage($sql);
// Try to execute that
if (!isSuccess($result = @$this->_ci->ExtensionsModel->executeQuery($sql)))
$resultQuery = @$this->_ci->ExtensionsModel->executeQuery($sql);
// If _not_ a success
if (!isSuccess($resultQuery))
{
$this->_errorOccurred = true;
$this->_printFailure(' error occurred while executing the query');
@@ -608,11 +632,11 @@ class ExtensionsLib
else
{
$this->_printMessage('Query result:');
var_dump($result->retval); // KEEP IT!!!
var_dump(getData($resultQuery)); // KEEP IT!!!
$this->_ci->eprintflib->printEOL();
}
}
}
}
}
}
$this->_printSuccess(!$this->_errorOccurred);
@@ -673,7 +697,7 @@ class ExtensionsLib
foreach ($this->SOFTLINK_TARGET_DIRECTORIES as $rootPath => $targetDirectories)
{
foreach ($targetDirectories as $key => $targetDirectory)
foreach ($targetDirectories as $targetDirectory)
{
if (file_exists($rootPath.$targetDirectory.'/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$extensionName))
{
@@ -727,7 +751,7 @@ class ExtensionsLib
// For every target directory
foreach ($this->SOFTLINK_TARGET_DIRECTORIES as $rootPath => $targetDirectories)
{
foreach ($targetDirectories as $key => $targetDirectory)
foreach ($targetDirectories as $targetDirectory)
{
// If destination of the symlink does not exist
if (!file_exists($rootPath.$targetDirectory.'/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$extensionName))
+18 -17
View File
@@ -18,6 +18,8 @@
if (! defined('BASEPATH')) exit('No direct script access allowed');
use \stdClass as stdClass;
/**
* Filter component logic
*/
@@ -92,8 +94,8 @@ class FilterCmptLib
private $_ci; // Code igniter instance
private $_filterUniqueId; // Unique id for this filter component
private $_filterType; //
private $_filterId; //
private $_filterType; //
private $_filterId; //
private $_app;
private $_datasetName;
@@ -133,6 +135,8 @@ class FilterCmptLib
//
if (!$this->_checkJSParameters()) return;
$filterCmptArray = array(); // default value
//
$filePath = findResource(APPPATH.'components/filters/', $this->_filterType, true);
if (!isEmptyString($filePath))
@@ -147,7 +151,7 @@ class FilterCmptLib
}
//
if (!isset($filterCmptArray))
if (!isset($filterCmptArray) && isEmptyArray($filterCmptArray))
{
$this->_setSession(error('Component definition file '.$this->_filterType.' not found'));
return;
@@ -156,7 +160,7 @@ class FilterCmptLib
//
if (!$this->_checkPHPParameters($filterCmptArray)) return;
//
//
$this->_initFilterCmpt($filterCmptArray);
//
@@ -340,7 +344,8 @@ class FilterCmptLib
if (in_array($selectedField, $fields))
{
// If the selected field is present in the list of the selected fields by the current filter
if (($pos = array_search($selectedField, $selectedFields)) !== false)
$pos = array_search($selectedField, $selectedFields);
if ($pos !== false)
{
// Then remove it and shift the rest of elements by one if needed
array_splice($selectedFields, $pos, 1);
@@ -453,7 +458,7 @@ class FilterCmptLib
// If not an empty array
if ($filterField != null)
{
//
//
if (isset($filterField->name) && isset($filterField->operation) && isset($filterField->condition)
&& !isEmptyString($filterField->name) && !isEmptyString($filterField->operation)
&& !isEmptyString($filterField->condition))
@@ -479,14 +484,14 @@ class FilterCmptLib
break;
}
}
else //
else //
{
$fine = false;
break;
}
}
//
//
if ($fine)
{
// Write changes into the session
@@ -640,9 +645,6 @@ class FilterCmptLib
// If filters were loaded
if (hasData($filters))
{
$childrenArray = array(); // contains all the children elements in a menu entry
$childrenPersonalArray = array(); // contains all the children elements in menu enty for personal filters
// Loops through loaded filters
foreach (getData($filters) as $filter)
{
@@ -977,12 +979,11 @@ class FilterCmptLib
{
$columnsNames = array();
foreach ($columns as $key => $obj)
// For each column
foreach ($columns as $obj)
{
if (isset($obj->name))
{
$columnsNames[] = $obj->name;
}
// If it is set the property name of the column
if (isset($obj->name)) $columnsNames[] = $obj->name;
}
return $columnsNames;
@@ -1209,7 +1210,7 @@ class FilterCmptLib
private function _getFilterName($filterJson)
{
$filterName = $filterJson->name; // always present, used as default
$trimedname = (isset($filterJson->namePhrase)?trim($filterJson->namePhrase):'');
// Filter name from phrases system
if (isset($filterJson->namePhrase) && !isEmptyString($filterJson->namePhrase))
{
+16 -5
View File
@@ -83,9 +83,19 @@ class NavigationLib
* Returns the structure for one level of the menu
*/
public function oneLevel(
$description, $link = '#', $children = null, $icon = '', $expand = false,
$subscriptDescription = null, $subscriptLinkClass = null, $subscriptLinkValue = null, $target = '',
$sort = null, $requiredPermissions = null, $subscriptLinkHref = '#')
$description,
$link = '#',
$children = null,
$icon = '',
$expand = false,
$subscriptDescription = null,
$subscriptLinkClass = null,
$subscriptLinkValue = null,
$target = '',
$sort = null,
$requiredPermissions = null,
$subscriptLinkHref = '#'
)
{
return array(
'description' => $description,
@@ -239,7 +249,8 @@ class NavigationLib
$filename = APPPATH.'config/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$ext->name.'/'.self::CONFIG_NAVIGATION_FILENAME;
if (file_exists($filename))
{
unset($config);
$config = array(); // default value
include($filename);
if (isset($config[$configName]) && is_array($config[$configName]))
@@ -294,7 +305,7 @@ class NavigationLib
}
else
{
foreach ($navigationArray as $key=>$row)
foreach ($navigationArray as $key => $row)
{
// Search for * Entries
if (mb_strpos($key, '*') === 0 || mb_strpos($key, '*') === mb_strlen($key) - 1)
+3 -1
View File
@@ -18,12 +18,14 @@
if (! defined('BASEPATH')) exit('No direct script access allowed');
use \stdClass as stdClass;
/**
*
*/
class SearchBarLib
{
//
// Error constats
const ERROR_WRONG_JSON = 'ERR001';
const ERROR_WRONG_SEARCHSTR = 'ERR002';
const ERROR_NO_TYPES = 'ERR003';