<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[FrontAccounting forum — deactivate_extension not dropping tables]]></title>
		<link>https://frontaccounting.com/punbb/viewtopic.php?id=5955</link>
		<atom:link href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=5955&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in deactivate_extension not dropping tables.]]></description>
		<lastBuildDate>Wed, 07 Oct 2015 05:43:13 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: deactivate_extension not dropping tables]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=24445#p24445</link>
			<description><![CDATA[<p>glad&nbsp; to hear that the core problem was solved.</p>]]></description>
			<author><![CDATA[null@example.com (kvvaradha)]]></author>
			<pubDate>Wed, 07 Oct 2015 05:43:13 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=24445#p24445</guid>
		</item>
		<item>
			<title><![CDATA[Re: deactivate_extension not dropping tables]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=24439#p24439</link>
			<description><![CDATA[<p>Thanks Janusz. </p><p>Very elegantly done avoiding another function (should it now be <strong>toggle_hooks</strong>? <img src="https://frontaccounting.com/punbb/img/smilies/wink.png" width="15" height="15" alt="wink" /> ). </p><p>It certainly was worth the wait.</p><p>Synched and <a href="https://github.com/apmuthu/frontaccounting/commit/85ed1f9af37e2728947d57632a54f1a0f2af1167">committed in my repo</a> as well.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Tue, 06 Oct 2015 17:39:02 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=24439#p24439</guid>
		</item>
		<item>
			<title><![CDATA[Re: deactivate_extension not dropping tables]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=24438#p24438</link>
			<description><![CDATA[<p>Issue has been fixed in <a href="http://https:/sourceforge.net/p/frontaccounting/git/ci/8a2ac7536a58c7860cbebba4f786f51f761ac2bf/">stable repo</a><br />Thanks for patient cooperation <img src="https://frontaccounting.com/punbb/img/smilies/wink.png" width="15" height="15" alt="wink" />.</p><p>Janusz</p>]]></description>
			<author><![CDATA[null@example.com (itronics)]]></author>
			<pubDate>Tue, 06 Oct 2015 07:41:07 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=24438#p24438</guid>
		</item>
		<item>
			<title><![CDATA[Re: deactivate_extension not dropping tables]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=24435#p24435</link>
			<description><![CDATA[<p>Ok,&nbsp; the module deactivation works right on my installation&nbsp; by accident, but surely there is some bug here. I will push solution to repo later today.</p><p>Janusz</p>]]></description>
			<author><![CDATA[null@example.com (itronics)]]></author>
			<pubDate>Tue, 06 Oct 2015 06:37:25 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=24435#p24435</guid>
		</item>
		<item>
			<title><![CDATA[Re: deactivate_extension not dropping tables]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=24430#p24430</link>
			<description><![CDATA[<p>My tests have been on a plain vanilla FA 2.3.24+ install and the problem exists in it. It is imperative to fix it in the stable version as well based on the <a href="https://github.com/apmuthu/frontaccounting/commit/f55b4168ee04d042b331bccbed39d2654c0a108d">commit in my repo</a>. The current <strong>activate_hooks</strong> is in itself a workaround on which the <strong>deactivate_hooks</strong> is based and the comment above the former would attest to this in <strong>includes/hooks.inc</strong> after the class definition:<br /></p><div class="codebox"><pre><code>/*
    Non active hooks are not included in $Hooks array, so we can use special function to 
    activate.
*/</code></pre></div><p>Only, in this case, at this point of entry into the hooks_invoke even the active hooks are not in it! There are a host of functions that are outside the hooks class definition that create a new instance of the hooks class and then invoke the hooks methods!</p><p>Install the extension in the default company and activate it for a non default company alone and then try to de-activate it and see if the tables get dropped.</p><p>Only the official <strong>dashboard</strong> extension has the drop sql in it. </p><p>Try to only install the dashboard extension (and not the theme) and then activate it and then de-activate it and you will see that the tables remain. At first I thought that it was to save the tables for a re-installation so that user changes are persistent but then most extensions drop the table if it exists before re-creating them during the activation phase and hence it gives us an illusion of having been deleted during deactivation unless the tables are checked just after deactivation.</p><p>The usage of XOR is may be standard even if not very widely used, but the usage of the hook_invoke by callback isn&#039;t where a simple <strong>if...else</strong> could have sufficed.</p><p>The real solution however, would be to make sure that the global <strong>$Hooks</strong> array gets pupulated earlier than this invocation and does not get overwritten thereafter. In fact, we have <strong>@kvvaradha</strong> to thank as this was investigated during the vetting of his <a href="https://github.com/kvvaradha/Simple-HRM-for-Frontaccounting">hrm</a> extension based on the <strong>dashboard</strong> skeleton.</p><p>It is pertinent to note that solution may lie in the fact that the extension install and uninstall works perfectly in <strong>includes/packages.inc</strong> wherein the $Hooks array gets populated with the active extensions in:<br /></p><div class="codebox"><pre><code>            if (($ext[&#039;active&#039;] == true) &amp;&amp; file_exists($path_to_root.&#039;/&#039;.$ext[&#039;path&#039;].&#039;/hooks.php&#039;))
            {
                // we need to include the new hooks file to activate extension
                include_once($path_to_root.&#039;/&#039;.$ext[&#039;path&#039;].&#039;/hooks.php&#039;);
                foreach($db_connections as $comp =&gt; $db)
                    activate_hooks($ext[&#039;package&#039;], $comp);
            }</code></pre></div><p>Perhaps something like this should precede the hooks_invoke in <strong>admin/inst_module.php</strong>.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Mon, 05 Oct 2015 04:45:21 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=24430#p24430</guid>
		</item>
		<item>
			<title><![CDATA[Re: deactivate_extension not dropping tables]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=24429#p24429</link>
			<description><![CDATA[<p>Well, it is always better to find exact reason of encountered problems than ommit it with workaround at random place where it first appeared, leaving the real solution for later. After testing both FA versions I can say this problem is absent in stable 2.3.24. I will investigate this issue further to fix the beta version. </p><p>NB The XOR usage in above code is rather standard - this is just simple test which is true if and only if&nbsp; &#039;active&#039; flag changes.<br />Janusz</p>]]></description>
			<author><![CDATA[null@example.com (itronics)]]></author>
			<pubDate>Sun, 04 Oct 2015 21:18:19 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=24429#p24429</guid>
		</item>
		<item>
			<title><![CDATA[Re: deactivate_extension not dropping tables]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=24424#p24424</link>
			<description><![CDATA[<p>First off, the current callback method of deactivating the extensions is simply not working as far as the dropping of the extension&#039;s tables are concerned - wonder when was the last time it worked, if ever. </p><p>Lines 213 to 225 of the current <strong>admin/inst_module.php</strong> file are:<br /></p><div class="codebox"><pre><code>    foreach($exts as $i =&gt; $ext) {
        if ($ext[&#039;package&#039;] &amp;&amp; ($ext[&#039;active&#039;] ^ check_value(&#039;Active&#039;.$i))) {
            if (!$ext[&#039;active&#039;])
                $activated = activate_hooks($ext[&#039;package&#039;], $comp);
            else
                $activated = hook_invoke($ext[&#039;package&#039;], check_value(&#039;Active&#039;.$i) ?
                 &#039;activate_extension&#039;:&#039;deactivate_extension&#039;, $comp, false);
            if ($activated !== null)
                $result &amp;= $activated;
            if ($activated || ($activated === null))
                $exts[$i][&#039;active&#039;] = check_value(&#039;Active&#039;.$i);
        }
    }</code></pre></div><p>The second line (first <strong>if</strong>) above has an <strong>XOR</strong> (^) which means that the code fragment is executed only if <strong>either</strong> <br /></p><ol class="decimal"><li><p>the extension was already active <strong>or </strong></p></li><li><p>the activate extension checkbox has just been ticked and submitted</p></li></ol><p><strong>but not both.</strong></p><p>The second <strong>&quot;if&quot;</strong> activates the extension using the direct function <strong>activate _hooks()</strong> if it was inactive which because of the XOR condition above would mean that the activate extension checkbox had just been ticked. This works correctly and the module gets installed. However, this does not happen through the callback portion of the <strong>hook_invoke()</strong> function through which it is never called. The use of the direct function <strong>activate _hooks()</strong> was necessary since the value of the <strong>$Hooks</strong> global array variable is empty when it enters the <strong>activate_extension()</strong> method by callback if the<strong> hook_invoke()</strong> was used.</p><p>The <strong>&quot;else&quot;</strong> of the second <strong>&quot;if&quot;</strong> triggers the callback only for the <strong>deactivate_extension()</strong> method when the activate extension checkbox has just been unticked whilst the extension was active. Here, the value of the <strong>$Hooks</strong> global array variable is empty when it enters the said <strong>deactivate_extension()</strong> method which exits without executing the deactivation sql if any. It is for this reason that the new direct function <strong>deactivate_hooks()</strong> was used to do the job.</p><p>The esoteric callback method in <strong>hook_invoke()</strong> seems to make the code quite a bit of a challenge for the average user to comprehend and I was initially blinded to conclude that the said <strong>deactivate_extension()</strong> method was never called. We should try to use simple and easy to understand constructs for ease of debugging / troubleshooting by the average user for mass trusted adoption.</p><p>Steps to reproduce:<br />1.&nbsp; Install and activate for one company any extension (currently, only <strong>dashboard</strong> extension has a drop sql separately) that creates tables and has a means to drop them as well. Alternatively create an extension that only creates one table and then on deactivation drops that table and then install and activate it for one company.<br />2. Now choose to deactivate it for the company for which it is currently active.<br />3. Check and find that the newly created table(s) have not been dropped despite deactivation.<br />4. Use my new function method and then repeat the steps above and you will find successful deactivation with the newly created table(s) dropped.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Sun, 04 Oct 2015 19:11:06 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=24424#p24424</guid>
		</item>
		<item>
			<title><![CDATA[Re: deactivate_extension not dropping tables]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=24422#p24422</link>
			<description><![CDATA[<p>Please describe exact scenario, where I can see this problem. I guess you mean the hook_invoke call in install_module.php file, but all seems to be right here.</p>]]></description>
			<author><![CDATA[null@example.com (itronics)]]></author>
			<pubDate>Sun, 04 Oct 2015 18:01:17 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=24422#p24422</guid>
		</item>
		<item>
			<title><![CDATA[Re: deactivate_extension not dropping tables]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=24407#p24407</link>
			<description><![CDATA[<p>I removed the indirect calling using hook_invoke method as the global <strong>$Hooks</strong> array is empty when it reaches inside the $hooks-&gt;deactivate_extension() function just as it does when it reaches inside the $hooks-&gt;activate_extension() function which was why the latter was used to overcome it. Unless we get to where and when the global $Hooks array gets populated (or re-initialised / overwritten), we will need this workaround.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Fri, 02 Oct 2015 10:10:37 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=24407#p24407</guid>
		</item>
		<item>
			<title><![CDATA[Re: deactivate_extension not dropping tables]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=24406#p24406</link>
			<description><![CDATA[<p>Function check_table is used to check existence of table , or specific field in table, and works properly, but you are right - for purity the lines should be swapped.<br /></p><div class="quotebox"><blockquote><p>The $hooks-&gt;deactivate_extension() is not being called anywhere in FA</p></blockquote></div><p>Well, in your patch you have removed the line where the function was used indirectly by hook_invoke method (the method name was passed to be executed in this function) as callback to drop the spare tables. Could you explain what was the reason for this?</p><p>Janusz</p>]]></description>
			<author><![CDATA[null@example.com (itronics)]]></author>
			<pubDate>Fri, 02 Oct 2015 06:54:39 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=24406#p24406</guid>
		</item>
		<item>
			<title><![CDATA[Re: deactivate_extension not dropping tables]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=24391#p24391</link>
			<description><![CDATA[<p>I must get Janusz to look at this first.</p><p>I am out of office right now, but will address him when I am back.</p><p>Joe</p>]]></description>
			<author><![CDATA[null@example.com (joe)]]></author>
			<pubDate>Tue, 29 Sep 2015 17:20:52 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=24391#p24391</guid>
		</item>
		<item>
			<title><![CDATA[Re: deactivate_extension not dropping tables]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=24389#p24389</link>
			<description><![CDATA[<p>@joe: you can update FA repo with the patch in the <a href="https://frontaccounting.com/punbb/viewtopic.php?pid=24359#p24359">5th post in this thread</a>.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Tue, 29 Sep 2015 14:22:27 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=24389#p24389</guid>
		</item>
		<item>
			<title><![CDATA[Re: deactivate_extension not dropping tables]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=24361#p24361</link>
			<description><![CDATA[<p>FA 2.3.x is designed for PHP 5 to 5.3 and a few have reported success with PHP 5.4 possibly with some mods.</p><p>In case you are testing with PHP 5.6+, please see what functions are deprecated / dropped in 5.4, 5.5 and then 5.6 and make sure you make appropriate changes / replacements.</p><p>There is no intention of the devs and myself in supporting any later versions of PHP other than 5.3 for FA v2.3.x. You are pretty much on your own here. </p><p>To assist others however, you may post your findings in a separate thread for such later PHP versions. Such findings posted in this thread will only serve to confuse end users - yes, it will make for big consultancy business...... but FA has been designed with simplicity in mind and for self service.</p><p>The code portion for activating extensions has not been touched in this fix and if it doesn&#039;t work for you now, then it never did in the first place prior to this fix as well.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Sun, 27 Sep 2015 03:52:05 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=24361#p24361</guid>
		</item>
		<item>
			<title><![CDATA[Re: deactivate_extension not dropping tables]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=24360#p24360</link>
			<description><![CDATA[<p>The above changes working for module deactivation. but its not working for the module activation. Please go through it once again. mine php version is 5.6.3 and its XAMPP.</p>]]></description>
			<author><![CDATA[null@example.com (kvvaradha)]]></author>
			<pubDate>Sun, 27 Sep 2015 02:53:25 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=24360#p24360</guid>
		</item>
		<item>
			<title><![CDATA[Re: deactivate_extension not dropping tables]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=24359#p24359</link>
			<description><![CDATA[<p>Fixed it! Pull it in from <a href="https://github.com/apmuthu/frontaccounting/commit/f55b4168ee04d042b331bccbed39d2654c0a108d">my repo</a>.</p><p>There was a missing <strong>function deactivate_hooks()</strong> which has now been added.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Sat, 26 Sep 2015 21:13:46 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=24359#p24359</guid>
		</item>
	</channel>
</rss>
