Some general fixes, deprecated rrdir (use Files::rmrf)

This commit is contained in:
fbsanchez 2021-07-01 00:37:13 +02:00
parent 074fbf916c
commit b3d88e6f6e
4 changed files with 46 additions and 10 deletions

View File

@ -26,6 +26,8 @@
* ============================================================================ * ============================================================================
*/ */
use PandoraFMS\Tools\Files;
global $config; global $config;
require_once $config['homedir'].'/include/functions_db.php'; require_once $config['homedir'].'/include/functions_db.php';
@ -2645,13 +2647,15 @@ class ConsoleSupervisor
{ {
global $config; global $config;
if ((int) $config['clean_phantomjs_cache'] !== 1) { if (isset($config['clean_phantomjs_cache']) !== true
|| (int) $config['clean_phantomjs_cache'] !== 1
) {
return; return;
} }
$cache_dir = $config['homedir'].'/attachment/cache'; $cache_dir = $config['homedir'].'/attachment/cache';
if (is_dir($cache_dir) === true) { if (is_dir($cache_dir) === true) {
rrmdir($cache_dir); Files::rmrf($cache_dir);
} }
// Clean process has ended. // Clean process has ended.

View File

@ -2241,7 +2241,10 @@ function db_get_lock(string $lockname, int $expiration_time=86400) :?int
global $config; global $config;
// Temporary disable to get a valid lock if any... // Temporary disable to get a valid lock if any...
$cache = $config['dbcache']; if (isset($config['dbcache']) === true) {
$cache = $config['dbcache'];
}
$config['dbcache'] = false; $config['dbcache'] = false;
$lock_status = db_get_value_sql( $lock_status = db_get_value_sql(
@ -2260,7 +2263,12 @@ function db_get_lock(string $lockname, int $expiration_time=86400) :?int
) )
); );
$config['dbcache'] = $cache; if (isset($cache) === true) {
$config['dbcache'] = $cache;
} else {
unset($config['dbcache']);
}
if ($lock_status === false) { if ($lock_status === false) {
return null; return null;
} }
@ -2268,7 +2276,12 @@ function db_get_lock(string $lockname, int $expiration_time=86400) :?int
return (int) $lock_status; return (int) $lock_status;
} }
$config['dbcache'] = $cache; if (isset($cache) === true) {
$config['dbcache'] = $cache;
} else {
unset($config['dbcache']);
}
return 0; return 0;
} }
@ -2285,7 +2298,11 @@ function db_get_lock(string $lockname, int $expiration_time=86400) :?int
function db_release_lock($lockname) function db_release_lock($lockname)
{ {
global $config; global $config;
$cache = $config['dbcache']; // Temporary disable to get a valid lock if any...
if (isset($config['dbcache']) === true) {
$cache = $config['dbcache'];
}
$config['dbcache'] = false; $config['dbcache'] = false;
$return = db_get_value_sql( $return = db_get_value_sql(
@ -2295,7 +2312,11 @@ function db_release_lock($lockname)
) )
); );
$config['dbcache'] = $cache; if (isset($cache) === true) {
$config['dbcache'] = $cache;
} else {
unset($config['dbcache']);
}
return $return; return $return;

View File

@ -244,6 +244,8 @@ function update_manager_get_messages()
* *
* @param string $dir Path to dir. * @param string $dir Path to dir.
* *
* @deprecated 755 Use Files::rmrf.
*
* @return void * @return void
*/ */
function rrmdir($dir) function rrmdir($dir)

View File

@ -113,9 +113,18 @@ class Files
} }
$zip = new \ZipArchive; $zip = new \ZipArchive;
if ($zip->open($file, (\ZipArchive::RDONLY & \ZipArchive::ER_READ)) === true) { if (defined('\ZipArchive::RDONLY') === true) {
$zip->close(); // PHP >= 7.4.
return true; if ($zip->open($file, (\ZipArchive::RDONLY)) === true) {
$zip->close();
return true;
}
} else {
// PHP < 7.4.
if ($zip->open($file, (\ZipArchive::CHECKCONS)) === true) {
$zip->close();
return true;
}
} }
return false; return false;