diff --git a/src/Cleaner/Caches.php b/src/Cleaner/Caches.php index 4fc9248..3ed5727 100644 --- a/src/Cleaner/Caches.php +++ b/src/Cleaner/Caches.php @@ -74,15 +74,15 @@ class Caches extends CleanerParent public function values(): array { - $res = []; + $stack = []; foreach (self::getDirs(DC_TPL_CACHE) as $path => $count) { - $res[] = new ValueDescriptor( + $stack[] = new ValueDescriptor( ns: $path, count: $count ); } - return $res; + return $stack; } public function execute(string $action, string $ns): bool diff --git a/src/Cleaner/Logs.php b/src/Cleaner/Logs.php index 8529dc4..08648d8 100644 --- a/src/Cleaner/Logs.php +++ b/src/Cleaner/Logs.php @@ -74,20 +74,22 @@ class Logs extends CleanerParent ->where($sql->orGroup(['blog_id IS NULL', 'blog_id IS NOT NULL'])) ->group('log_table'); - $rs = $sql->select(); - if (is_null($rs) || $rs->isEmpty()) { + $record = $sql->select(); + if (is_null($record) || $record->isEmpty()) { return []; } - $res = []; - while ($rs->fetch()) { - $res[] = new ValueDescriptor( - ns: (string) $rs->f('log_table'), - count: (int) $rs->f('counter') - ); + $stack = []; + while ($record->fetch()) { + if (is_string($record->f('log_table')) && is_numeric($record->f('counter'))) { + $stack[] = new ValueDescriptor( + ns: $record->f('log_table'), + count: (int) $record->f('counter') + ); + } } - return $res; + return $stack; } public function execute(string $action, string $ns): bool diff --git a/src/Cleaner/Plugins.php b/src/Cleaner/Plugins.php index a3f021a..2125520 100644 --- a/src/Cleaner/Plugins.php +++ b/src/Cleaner/Plugins.php @@ -61,15 +61,15 @@ class Plugins extends CleanerParent $dirs = self::getDirs(DC_PLUGINS_ROOT); sort($dirs); - $res = []; + $stack = []; foreach ($dirs as $path => $count) { - $res[] = new ValueDescriptor( + $stack[] = new ValueDescriptor( ns: $path, count: $count ); } - return $res; + return $stack; } public function execute(string $action, string $ns): bool diff --git a/src/Cleaner/Preferences.php b/src/Cleaner/Preferences.php index 80287d4..96e960e 100644 --- a/src/Cleaner/Preferences.php +++ b/src/Cleaner/Preferences.php @@ -105,20 +105,22 @@ class Preferences extends CleanerParent ->where($sql->orGroup(['user_id IS NULL', 'user_id IS NOT NULL'])) ->group('pref_ws'); - $rs = $sql->select(); - if (is_null($rs) || $rs->isEmpty()) { + $record = $sql->select(); + if (is_null($record) || $record->isEmpty()) { return []; } - $res = []; - while ($rs->fetch()) { - $res[] = new ValueDescriptor( - ns: (string) $rs->f('pref_ws'), - count: (int) $rs->f('counter') - ); + $stack = []; + while ($record->fetch()) { + if (is_string($record->f('pref_ws')) && is_numeric($record->f('counter'))) { + $stack[] = new ValueDescriptor( + ns: $record->f('pref_ws'), + count: (int) $record->f('counter') + ); + } } - return $res; + return $stack; } public function related(string $ns): array @@ -133,20 +135,22 @@ class Preferences extends CleanerParent ->and('pref_ws = ' . $sql->quote($ns)) ->group('pref_id'); - $rs = $sql->select(); - if (is_null($rs) || $rs->isEmpty()) { + $record = $sql->select(); + if (is_null($record) || $record->isEmpty()) { return []; } - $res = []; - while ($rs->fetch()) { - $res[] = new ValueDescriptor( - id: (string) $rs->f('pref_id'), - count: (int) $rs->f('counter') - ); + $stack = []; + while ($record->fetch()) { + if (is_string($record->f('pref_id')) && is_numeric($record->f('counter'))) { + $stack[] = new ValueDescriptor( + id: $record->f('pref_id'), + count: (int) $record->f('counter') + ); + } } - return $res; + return $stack; } public function execute(string $action, string $ns): bool diff --git a/src/Cleaner/Settings.php b/src/Cleaner/Settings.php index 051c0aa..4de3604 100644 --- a/src/Cleaner/Settings.php +++ b/src/Cleaner/Settings.php @@ -109,20 +109,22 @@ class Settings extends CleanerParent ->where($sql->orGroup(['blog_id IS NULL', 'blog_id IS NOT NULL'])) ->group('setting_ns'); - $rs = $sql->select(); - if (is_null($rs) || $rs->isEmpty()) { + $record = $sql->select(); + if (is_null($record) || $record->isEmpty()) { return []; } - $res = []; - while ($rs->fetch()) { - $res[] = new ValueDescriptor( - ns: (string) $rs->f('setting_ns'), - count: (int) $rs->f('counter') - ); + $stack = []; + while ($record->fetch()) { + if (is_string($record->f('setting_ns')) && is_numeric($record->f('counter'))) { + $stack[] = new ValueDescriptor( + ns: $record->f('setting_ns'), + count: (int) $record->f('counter') + ); + } } - return $res; + return $stack; } public function related(string $ns): array @@ -137,20 +139,22 @@ class Settings extends CleanerParent ->and('setting_ns = ' . $sql->quote($ns)) ->group('setting_id'); - $rs = $sql->select(); - if (is_null($rs) || $rs->isEmpty()) { + $record = $sql->select(); + if (is_null($record) || $record->isEmpty()) { return []; } - $res = []; - while ($rs->fetch()) { - $res[] = new ValueDescriptor( - id: (string) $rs->f('setting_id'), - count: (int) $rs->f('counter') - ); + $stack = []; + while ($record->fetch()) { + if (is_string($record->f('setting_id')) && is_numeric($record->f('counter'))) { + $stack[] = new ValueDescriptor( + id: $record->f('setting_id'), + count: (int) $record->f('counter') + ); + } } - return $res; + return $stack; } public function execute(string $action, string $ns): bool diff --git a/src/Cleaner/Tables.php b/src/Cleaner/Tables.php index 0697767..668eb08 100644 --- a/src/Cleaner/Tables.php +++ b/src/Cleaner/Tables.php @@ -92,10 +92,10 @@ class Tables extends CleanerParent public function values(): array { - $object = AbstractSchema::init(dcCore::app()->con); - $tables = $object->getTables(); + $schema = AbstractSchema::init(dcCore::app()->con); + $tables = $schema->getTables(); - $res = []; + $stack = []; foreach ($tables as $k => $v) { // get only tables with dotclear prefix if ('' != dcCore::app()->prefix) { @@ -105,15 +105,16 @@ class Tables extends CleanerParent $v = $m[1]; } - $sql = new SelectStatement(); + $sql = new SelectStatement(); + $count = $sql->from($tables[$k])->fields([$sql->count('*')])->select()?->f(0); - $res[] = new ValueDescriptor( + $stack[] = new ValueDescriptor( ns: (string) $v, - count: (int) $sql->from($tables[$k])->fields([$sql->count('*')])->select()?->f(0) + count: is_numeric($count) ? (int) $count : 0 ); } - return $res; + return $stack; } public function execute(string $action, string $ns): bool diff --git a/src/Cleaner/Themes.php b/src/Cleaner/Themes.php index 3655aca..53e3f67 100644 --- a/src/Cleaner/Themes.php +++ b/src/Cleaner/Themes.php @@ -66,15 +66,15 @@ class Themes extends CleanerParent $dirs = self::getDirs($path); sort($dirs); - $res = []; + $stack = []; foreach ($dirs as $path => $count) { - $res[] = new ValueDescriptor( + $stack[] = new ValueDescriptor( ns: $path, count: $count ); } - return $res; + return $stack; } public function execute(string $action, string $ns): bool diff --git a/src/Cleaner/Vars.php b/src/Cleaner/Vars.php index 7f595c4..3d183e1 100644 --- a/src/Cleaner/Vars.php +++ b/src/Cleaner/Vars.php @@ -59,15 +59,15 @@ class Vars extends CleanerParent public function values(): array { - $res = []; + $stack = []; foreach (self::getDirs(DC_VAR) as $path => $count) { - $res[] = new ValueDescriptor( + $stack[] = new ValueDescriptor( ns: $path, count: $count ); } - return $res; + return $stack; } public function execute(string $action, string $ns): bool diff --git a/src/Cleaner/Versions.php b/src/Cleaner/Versions.php index fed4799..de2ce3a 100644 --- a/src/Cleaner/Versions.php +++ b/src/Cleaner/Versions.php @@ -80,16 +80,16 @@ class Versions extends CleanerParent return []; } - $res = []; + $stack = []; while ($rs->fetch()) { - $res[] = new ValueDescriptor( + $stack[] = new ValueDescriptor( ns: (string) $rs->f('module'), id: (string) $rs->f('version'), count: 1 ); } - return $res; + return $stack; } public function execute(string $action, string $ns): bool