From 83064d68c7ce6b0cd583343e1fe130936a80bcdf Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Thu, 29 Jul 2021 16:55:49 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B04092=20Setup=20:=20symlink=20option=20no?= =?UTF-8?q?w=20always=20displayed=20if=20functionality=20enabled=20Previou?= =?UTF-8?q?sly=20we=20were=20also=20testing=20for=20flag=20presence.=20In?= =?UTF-8?q?=20consequence=20the=20confirmation=20dialog=20when=20uncheckin?= =?UTF-8?q?g=20the=20option=20is=20also=20removed=20(we=20can=20enable=20b?= =?UTF-8?q?ack=20the=20option=20using=20the=20setup)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup/ajax.dataloader.php | 2 +- setup/compiler.class.inc.php | 64 +++++++++++++++++++++------------ setup/wizardsteps.class.inc.php | 15 +++----- 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/setup/ajax.dataloader.php b/setup/ajax.dataloader.php index cc9ad9fa7..72716ed58 100644 --- a/setup/ajax.dataloader.php +++ b/setup/ajax.dataloader.php @@ -180,7 +180,7 @@ try $sUseSymbolicLinks = Utils::ReadParam('bUseSymbolicLinks', false); $bUseSymbolicLinks = ($sUseSymbolicLinks === 'true'); MFCompiler::SetUseSymbolicLinksFlag($bUseSymbolicLinks); - echo "toggle useSymbolicLInks file : $bUseSymbolicLinks"; + echo "toggle useSymbolicLinks flag : $bUseSymbolicLinks"; break; default: diff --git a/setup/compiler.class.inc.php b/setup/compiler.class.inc.php index 1ad3d11f4..a9c689835 100644 --- a/setup/compiler.class.inc.php +++ b/setup/compiler.class.inc.php @@ -58,6 +58,8 @@ class MFCompiler * If this file is present, then we will compile to symlink ! * * @var string + * + * @since 3.0.0 N°4092 */ public const USE_SYMBOLIC_LINKS_FILE_PATH = APPROOT.'data/.compilation-symlinks'; @@ -121,47 +123,63 @@ class MFCompiler } /** - * @param bool $bForce if true then will just check file existence + * @return bool if flag is present true, false otherwise * - * @return bool possible return values : - * * always false if not in dev env - * * `symlink` function non existent : false - * * if flag is present true, false otherwise - * - * @uses utils::IsDevelopmentEnvironment() - * @uses \function_exists() * @uses \file_exists() * @uses USE_SYMBOLIC_LINKS_FILE_PATH * - * @since 3.0.0 + * @since 3.0.0 N°4092 */ - public static function IsUseSymbolicLinksFlagPresent(bool $bForce = false): bool + public static function IsUseSymbolicLinksFlagPresent(): bool { - if (!$bForce) { - if (!utils::IsDevelopmentEnvironment()) { - return false; - } + return (file_exists(static::USE_SYMBOLIC_LINKS_FILE_PATH)); + } - if (!function_exists('symlink')) { - return false; - } + /** + * This is to check if the functionality can be used. As this is really only useful for developers, + * this is strictly limited and not available on any iTop instance ! + * + * @return bool Check that the symlinks flag can be used + * * always false if not in dev env + * * `symlink` function non-existent : false + * * true otherwise + * + * @uses utils::IsDevelopmentEnvironment() + * @uses \function_exists() + * + * @since 3.0.0 N°4092 + */ + public static function IsUseSymbolicLinksFlagCanBeUsed(): bool + { + if (false === utils::IsDevelopmentEnvironment()) { + return false; } - return (file_exists(static::USE_SYMBOLIC_LINKS_FILE_PATH)); + if (false === function_exists('symlink')) { + return false; + } + + return true; } /** * @param bool $bUseSymbolicLinks * - * @since 3.0.0 method creation * @uses USE_SYMBOLIC_LINKS_FILE_PATH + * + * @since 3.0.0 N°4092 */ public static function SetUseSymbolicLinksFlag(bool $bUseSymbolicLinks): void { - $bHasUseSymlinksFile = static::IsUseSymbolicLinksFlagPresent(true); + if (!static::IsUseSymbolicLinksFlagCanBeUsed()) { + // functionality cannot be used, so we're doing nothing ! + return; + } + + $bIsUseSymlinksFlagPresent = (static::IsUseSymbolicLinksFlagPresent()); if ($bUseSymbolicLinks) { - if ($bHasUseSymlinksFile) { + if ($bIsUseSymlinksFlagPresent) { return; } @@ -170,7 +188,7 @@ class MFCompiler return; } - if (!$bHasUseSymlinksFile) { + if (!$bIsUseSymlinksFlagPresent) { return; } unlink(static::USE_SYMBOLIC_LINKS_FILE_PATH); @@ -205,7 +223,7 @@ class MFCompiler { if (is_null($bUseSymbolicLinks)) { $bUseSymbolicLinks = false; - if (self::IsUseSymbolicLinksFlagPresent()) { + if (self::IsUseSymbolicLinksFlagCanBeUsed() && self::IsUseSymbolicLinksFlagPresent()) { // We are only overriding the useSymLinks option if the consumer didn't specify anything // The toolkit always send this parameter for example, but not the Designer Connector $bUseSymbolicLinks = true; diff --git a/setup/wizardsteps.class.inc.php b/setup/wizardsteps.class.inc.php index 3294542c2..0a0d092fd 100644 --- a/setup/wizardsteps.class.inc.php +++ b/setup/wizardsteps.class.inc.php @@ -943,7 +943,7 @@ EOF }} /** - * Miscellaneous Parameters (URL, Sample Data) + * Miscellaneous Parameters (URL, Sample Data) when installing from scratch */ class WizStepMiscParams extends WizardStep { @@ -1162,22 +1162,17 @@ class WizStepUpgradeMiscParams extends WizardStep EOF ); - if (MFCompiler::IsUseSymbolicLinksFlagPresent()) { + if (MFCompiler::IsUseSymbolicLinksFlagCanBeUsed()) { + $sChecked = (MFCompiler::IsUseSymbolicLinksFlagPresent()) ? ' checked' : ''; + $oPage->add('
'); $oPage->add('Dev parameters'); - $oPage->p('
'); $oPage->add_ready_script(<<<'JS' $("#use-symbolic-links").on("click", function() { var $this = $(this), bUseSymbolicLinks = $this.prop("checked"); - if (!bUseSymbolicLinks){ - if (!window.confirm("This will disable symbolic links generation.\nYou'll need the toolkit to restore this option.\n\nAre you sure ?")) { - $this.prop("checked", true); - return; - } - } - var sAuthent = $('#authent_token').val(); var oAjaxParams = { operation: 'toggle_use_symbolic_links', bUseSymbolicLinks: bUseSymbolicLinks, authent: sAuthent}; $.post(GetAbsoluteUrlAppRoot()+'setup/ajax.dataloader.php', oAjaxParams);