diff --git a/DataStorage/Cache/Connection/NullCache.php b/DataStorage/Cache/Connection/NullCache.php index 24ddd1e6a..595a8e09c 100644 --- a/DataStorage/Cache/Connection/NullCache.php +++ b/DataStorage/Cache/Connection/NullCache.php @@ -38,6 +38,20 @@ final class NullCache extends ConnectionAbstract { } + /** + * {@inheritdoc} + */ + public function increment(int|string $key, int $value = 1) : void + { + } + + /** + * {@inheritdoc} + */ + public function decrement(int|string $key, int $value = 1) : void + { + } + /** * {@inheritdoc} */ diff --git a/Message/Mail/MailHandler.php b/Message/Mail/MailHandler.php index 03483ee45..401ddf006 100644 --- a/Message/Mail/MailHandler.php +++ b/Message/Mail/MailHandler.php @@ -348,7 +348,7 @@ class MailHandler $mailerToolFmt = '%s -oi -t'; } - $mailerTool = \sprintf($mailerToolFmt, \escapeshellcmd($this->sendmail), $mail->sender); + $mailerTool = \sprintf($mailerToolFmt, \escapeshellcmd($this->mailerTool), $mail->sender); $con = \popen($mailerTool, 'w'); if ($con === false) { diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index 163bb4b72..b490ab78e 100644 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -369,6 +369,7 @@ final class ModuleManager return true; } catch (\Exception $e) { + echo $e->getMessage(); return false; // @codeCoverageIgnore } } @@ -489,7 +490,7 @@ final class ModuleManager { $installed = $this->getInstalledModules(false); if (isset($installed[$module])) { - return false; + return true; } if (!\is_file($this->modulePath . $module . '/Admin/Installer.php')) { diff --git a/Module/UninstallerAbstract.php b/Module/UninstallerAbstract.php index 5955b5f05..a4bd104d2 100644 --- a/Module/UninstallerAbstract.php +++ b/Module/UninstallerAbstract.php @@ -40,163 +40,26 @@ abstract class UninstallerAbstract */ public static function uninstall(DatabasePool $dbPool, ModuleInfo $info) : void { - self::uninitRoutes($info, $appInfo); - self::uninitHooks($info, $appInfo); - + self::deactivate($dbPool, $info); self::dropTables($dbPool, $info); self::unregisterFromDatabase($dbPool, $info); } /** - * Uninstall routes. + * Activate after install. * - * @param string $destRoutePath Destination route path - * @param string $srcRoutePath Source route path + * @param DatabasePool $dbPool Database instance + * @param ModuleInfo $info Module info * * @return void * * @since 1.0.0 */ - private static function uninitRoutes(string $destRoutePath, string $srcRoutePath) : void + protected static function deactivate(DatabasePool $dbPool, ModuleInfo $info) : void { - $directories = new Directory(\dirname($info->getPath()) . '/Admin/Routes'); - - /** @var Directory|File $child */ - foreach ($directories as $child) { - if ($child instanceof Directory) { - foreach ($child as $file) { - if (!\is_dir(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php')) - || ($appInfo !== null && \basename($file->getName(), '.php') !== $appInfo->getInternalName()) - ) { - continue; - } - - self::uninstallRoutes(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php') . '/Routes.php', $file->getPath()); - } - } elseif ($child instanceof File) { - if (!\is_dir(__DIR__ . '/../../' . $child->getName()) - || ($appInfo !== null && \basename($child->getName(), '.php') !== $appInfo->getInternalName()) - ) { - continue; - } - - self::uninstallRoutes(__DIR__ . '/../../' . $child->getName() . '/Routes.php', $child->getPath()); - } - } - } - - /** - * Uninstall routes. - * - * @param string $destRoutePath Destination route path - * @param string $srcRoutePath Source route path - * - * @return void - * - * @throws PermissionException - * - * @since 1.0.0 - */ - protected static function uninstallRoutes(string $destRoutePath, string $srcRoutePath) : void - { - if (!\is_file($destRoutePath) - || !\is_file($srcRoutePath) - ) { - return; - } - - if (!\is_file($destRoutePath)) { - throw new PathException($destRoutePath); - } - - if (!\is_writable($destRoutePath)) { - throw new PermissionException($destRoutePath); - } - - /** @noinspection PhpIncludeInspection */ - $appRoutes = include $destRoutePath; - /** @noinspection PhpIncludeInspection */ - $moduleRoutes = include $srcRoutePath; - - $appRoutes = ArrayUtils::array_diff_assoc_recursive($appRoutes, $moduleRoutes); - - \file_put_contents($destRoutePath, 'getPath()) . '/Admin/Hooks'); - - /** @var Directory|File $child */ - foreach ($directories as $child) { - if ($child instanceof Directory) { - foreach ($child as $file) { - if (!\is_dir(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php')) - || ($appInfo !== null && \basename($file->getName(), '.php') !== $appInfo->getInternalName()) - ) { - continue; - } - - self::uninstallHooks(__DIR__ . '/../../' . $child->getName() . '/' . \basename($file->getName(), '.php') . '/Hooks.php', $file->getPath()); - } - } elseif ($child instanceof File) { - if (!\is_dir(__DIR__ . '/../../' . $child->getName()) - || ($appInfo !== null && \basename($child->getName(), '.php') !== $appInfo->getInternalName()) - ) { - continue; - } - - self::uninstallHooks(__DIR__ . '/../../' . $child->getName() . '/Hooks.php', $child->getPath()); - } - } - } - - /** - * Uninstall hooks. - * - * @param string $destHookPath Destination hook path - * @param string $srcHookPath Source hook path - * - * @return void - * - * @throws PermissionException - * - * @since 1.0.0 - */ - protected static function uninstallHooks(string $destHookPath, string $srcHookPath) : void - { - if (!\is_file($destHookPath) - || !\is_file($srcHookPath) - ) { - return; - } - - if (!\is_file($destHookPath)) { - throw new PathException($destHookPath); - } - - if (!\is_writable($destHookPath)) { - throw new PermissionException($destHookPath); - } - - /** @noinspection PhpIncludeInspection */ - $appHooks = include $destHookPath; - /** @noinspection PhpIncludeInspection */ - $moduleHooks = include $srcHookPath; - - $appHooks = ArrayUtils::array_diff_assoc_recursive($appHooks, $moduleHooks); - - \file_put_contents($destHookPath, 'getDirectory() . '\Admin\Status'; + $class::deactivate($dbPool, $info); } /** diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index 03296c840..4fe49df1a 100644 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -436,8 +436,8 @@ final class ArrayUtils { $diff = []; foreach ($values1 as $key => $value) { - if (!\is_array($value)) { - if (!array_key_exists($key, $value2) || !\is_array($values2[$key])) { + if (\is_array($value)) { + if (!array_key_exists($key, $values2) || !\is_array($values2[$key])) { $diff[$key] = $value; } else { $subDiff = self::array_diff_assoc_recursive($value, $values2[$key]); @@ -445,8 +445,8 @@ final class ArrayUtils $diff[$key] = $subDiff; } } - } elseif ($values[$key] !== $value || !\array_key_exists($key, $values2)) { - $diff[$key] == $value; + } elseif (!\array_key_exists($key, $values2) || $values2[$key] !== $value) { + $diff[$key] = $value; } } diff --git a/Utils/IO/Csv/CsvSettings.php b/Utils/IO/Csv/CsvSettings.php index 696acb40d..a8b664426 100644 --- a/Utils/IO/Csv/CsvSettings.php +++ b/Utils/IO/Csv/CsvSettings.php @@ -74,4 +74,48 @@ class CsvSettings return $results[0]; } + + /** + * Get csv string delimiter based on string content. + * + * @param string $content File content + * @param int $checkLines Lines to check for evaluation + * @param string[] $delimiters Potential delimiters + * + * @return string + * + * @since 1.0.0 + */ + public static function getStringDelimiter(string $content, int $checkLines = 2, array $delimiters = [',', "\t", ';', '|', ':']) : string + { + $results = []; + $lines = \explode("\n", $content); + $i = 0; + + do { + $line = $lines[$i]; + foreach ($delimiters as $delimiter) { + $regExp = '/[' . $delimiter . ']/'; + $fields = \preg_split($regExp, $line); + + if ($fields === false) { + return ';'; // @codeCoverageIgnore + } + + if (\count($fields) > 1) { + if (!empty($results[$delimiter])) { + ++$results[$delimiter]; + } else { + $results[$delimiter] = 1; + } + } + } + + ++$i; + } while ($i < $checkLines); + + $results = \array_keys($results, \max($results)); + + return $results[0]; + } } diff --git a/Views/ViewAbstract.php b/Views/ViewAbstract.php index e6b04eaaa..9c4da3af0 100644 --- a/Views/ViewAbstract.php +++ b/Views/ViewAbstract.php @@ -247,7 +247,6 @@ abstract class ViewAbstract implements RenderableInterface } catch (\Throwable $e) { \ob_end_clean(); $ob = ''; - echo $e->getMessage(); } finally { return $ob; } diff --git a/tests/Message/Mail/MailHandlerTest.php b/tests/Message/Mail/MailHandlerTest.php index 64024e319..d89dae788 100644 --- a/tests/Message/Mail/MailHandlerTest.php +++ b/tests/Message/Mail/MailHandlerTest.php @@ -16,7 +16,6 @@ namespace phpOMS\tests\Message; require_once __DIR__ . '/../../Autoloader.php'; -use phpOMS\Message\Mail\Mail; use phpOMS\Message\Mail\MailHandler; use phpOMS\Message\Mail\SubmitType; use phpOMS\Message\Mail\Email; @@ -30,17 +29,17 @@ use phpOMS\Message\Mail\Imap; class MailHandlerTest extends \PHPUnit\Framework\TestCase { public function testSendTextWithMail() : void - {/* + { $mailer = new MailHandler(); $mailer->setMailer(SubmitType::MAIL); $mail = new Email(); - $mail->setFrom('d.eichhorn@orange-management.org', 'Dennis Eichhorn'); - $mail->addTo('coyle.maguire@googlemail.com', 'Donald Duck'); + $mail->setFrom('dennis.eichhorn@orange-management.org', 'Dennis Eichhorn'); + $mail->addTo('info@orange-management.org', 'Dennis Eichhorn'); $mail->subject = 'Test email'; $mail->body = 'This is some content'; - self::assertTrue($mailer->send($mail));*/ + self::assertTrue($mailer->send($mail)); } public function testReceiveMailWithImap() : void