<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>custom script &#8211; Aimeos</title>
	<atom:link href="https://aimeos.org/tips/tag/custom-script/feed/" rel="self" type="application/rss+xml" />
	<link>https://aimeos.org/tips</link>
	<description>ultra fast PHP e-commerce framework</description>
	<lastBuildDate>Mon, 29 Jul 2019 17:20:41 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.7.8</generator>

<image>
	<url>https://aimeos.org/tips/wp-content/uploads/2019/09/Aimeos_e_200-100x104.png</url>
	<title>custom script &#8211; Aimeos</title>
	<link>https://aimeos.org/tips</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to execute scripts after installing TYPO3 extensions</title>
		<link>https://aimeos.org/tips/how-to-execute-scripts-after-installing-typo3-extensions/</link>
					<comments>https://aimeos.org/tips/how-to-execute-scripts-after-installing-typo3-extensions/#comments</comments>
		
		<dc:creator><![CDATA[aimeos]]></dc:creator>
		<pubDate>Thu, 12 Feb 2015 09:58:19 +0000</pubDate>
				<category><![CDATA[TYPO3]]></category>
		<category><![CDATA[custom script]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[installation]]></category>
		<guid isPermaLink="false">http://aimeos.org/tips/?p=35</guid>

					<description><![CDATA[Extensions are a great way to add features to the TYPO3 CMS and there are extension for virtually everything! Simply download them from the TYPO3 extension repository and install them via the Extension Manager in the TYPO3 back-end. So far<span class="ellipsis">&#8230;</span><div class="read-more"><a href="https://aimeos.org/tips/how-to-execute-scripts-after-installing-typo3-extensions/">Read more <span class="screen-reader-text">How to execute scripts after installing TYPO3 extensions</span><span class="meta-nav"> &#8250;</span></a></div><!-- end of .read-more -->]]></description>
										<content:encoded><![CDATA[<p>Extensions are a great way to add features to the TYPO3 CMS and there are extension for virtually everything! Simply download them from the <a title="TYPO3 extension repository" href="http://typo3.org/extensions/repository/">TYPO3 extension repository</a> and install them via the Extension Manager in the TYPO3 back-end. So far so good &#8230;</p>
<p>Often, the remaining tasks of configuring the extension, adding new pages with the plug-ins from the extension or importing required data into the database becomes much more cumbersome. Why can&#8217;t life be not as easy as in other CMS? Just click and everything works?</p>
<p><span id="more-35"></span></p>
<h2>Yes, we can!</h2>
<p>The infrastructure for performing additional tasks after installing extensions is part of TYPO3 since some time. At least since TYPO3 6.2 it works flawlessly, before your way may vary. The trick is to utilize the <strong>signal/slot mechanism</strong> to connect to the Extension Management service and listen for signals emitted after an extension was installed.</p>
<p>In the <a title="Aimeos TYPO3 web shop extension" href="http://typo3.org/extensions/repository/view/aimeos">Aimeos TYPO3 web shop extension</a> we&#8217;ve added the following code to the <strong><a title="Aimeos TYPO3 ext_localconf.php code" href="https://github.com/aimeos/aimeos-typo3/blob/master/ext_localconf.php">ext_localconf.php</a></strong>:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="php"><ol><li class="li1"><pre class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span>TYPO3_MODE <span class="sy0">===</span> <span class="st_h">'BE'</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></pre></li><li class="li1"><pre class="de1">    <span class="re0">$class</span> <span class="sy0">=</span> <span class="st_h">'TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher'</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1">    <span class="re0">$dispatcher</span> <span class="sy0">=</span> \TYPO3\CMS\Core\Utility\GeneralUtility<span class="sy0">::</span><span class="me2">makeInstance</span><span class="br0">&#40;</span><span class="re0">$class</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1">    <span class="re0">$dispatcher</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>connect<span class="br0">&#40;</span></pre></li><li class="li1"><pre class="de1">        <span class="st_h">'TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService'</span><span class="sy0">,</span></pre></li><li class="li1"><pre class="de1">        <span class="st_h">'hasInstalledExtensions'</span><span class="sy0">,</span></pre></li><li class="li1"><pre class="de1">        <span class="st_h">'Aimeos\\Aimeos\\Setup'</span><span class="sy0">,</span></pre></li><li class="li1"><pre class="de1">        <span class="st_h">'executeOnSignal'</span></pre></li><li class="li1"><pre class="de1">    <span class="br0">&#41;</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1"><span class="br0">&#125;</span></pre></li></ol></div></div></div></div></div></div></div>


<p>The first line ensures that we are connecting only to the Extension Management service if we are in the back-end. If you leave this line out, your script would connect at every front-end request too, which would only slow down response times. The next two lines instantiates the signal/slot dispatcher class and the <code>makeInstance()</code> method of the <code>GeneralUtility</code> class does a good job.</p>
<div class="caution">Don&#8217;t use the PHP &#8220;new&#8221; operator for creating the class instance! This would create one instance each time the code is executed instead of sharing a common instance during the request.</div>
<p>The remaining lines connect your method <code>executeOnSignal()</code> of your namespaced class <code>Aimeos\Aimeos\Setup</code> to the Extension Management service whose class name is handed over as first parameter. Here we are listening to the <code>hasInstalledExtensions</code> signal, that is emitted by the service after an extension has been installed. The key of the installed extension will be passed as first parameter to our method.</p>
<div class="note">There&#8217;s another signal that is emitted by the Extension Management service named <code>willInstallExtensions</code>. By listening to this signal, your script can be informed about which extensions are going to be installed next. An array of extension keys is given in this case.</div>
<h2>Do what you need</h2>
<p>At last, you need to create a class that contains the code to be executed after an extension is installed. The Aimeos TYPO3 extension contains a <a title="Aimeos TYPO3 setup class code" href="https://github.com/aimeos/aimeos-typo3/blob/master/Classes/Setup.php"><code>Setup</code> class</a> in the <code>Classes/</code> directory of the extension with a method named <code>executeOnSignal()</code> to care about this. The basic code of this class is:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="php"><ol><li class="li1"><pre class="de1"><span class="sy0">&amp;</span>lt<span class="sy0">;</span>?php</pre></li><li class="li1"><pre class="de1">&nbsp;</pre></li><li class="li1"><pre class="de1"><span class="kw2">namespace</span> Aimeos\Aimeos<span class="sy0">;</span></pre></li><li class="li1"><pre class="de1">&nbsp;</pre></li><li class="li1"><pre class="de1"><span class="kw2">class</span> Setup</pre></li><li class="li1"><pre class="de1"><span class="br0">&#123;</span></pre></li><li class="li1"><pre class="de1">    <span class="kw2">public</span> <span class="kw2">function</span> executeOnSignal<span class="br0">&#40;</span> <span class="re0">$extname</span> <span class="sy0">=</span> <span class="kw4">null</span> <span class="br0">&#41;</span></pre></li><li class="li1"><pre class="de1">    <span class="br0">&#123;</span></pre></li><li class="li1"><pre class="de1">        <span class="kw1">if</span><span class="br0">&#40;</span> <span class="re0">$extname</span> <span class="sy0">!==</span> <span class="st_h">'aimeos'</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span></pre></li><li class="li1"><pre class="de1">            <span class="kw1">return</span><span class="sy0">;</span></pre></li><li class="li1"><pre class="de1">        <span class="br0">&#125;</span></pre></li><li class="li1"><pre class="de1">&nbsp;</pre></li><li class="li1"><pre class="de1">        <span class="co1">// your code</span></pre></li><li class="li1"><pre class="de1">    <span class="br0">&#125;</span></pre></li><li class="li1"><pre class="de1"><span class="br0">&#125;</span></pre></li></ol></div></div></div></div></div></div></div>


<p>The <strong>namespace declaration</strong> is important but <strong>must be adapted to your extension</strong>. The first namespace part is the vendor name, e.g. the name of your company. The second part is the extension key with the first letter uppercased. If your extension key contains an underscore, then the underscore is removed and the next character transformed to uppercase as well, e.g. the <code>boostrap_package</code> uses <code>BootstrapPackage</code> as the second namespace part.</p>
<p>You are free to use any valid class and method name in your extension. Only make sure that the third and fourth parameter of the <code>connect()</code> method call are named appropriately. Also, ensure that your class and method are neither abstract nor static so an instance can be created. Like said above, the key name of the extension that has been installed is given as first parameter to your method. For compatibility reasons, you should make that parameter optional by assigning a default value of <code>null</code>.</p>
<div class="tip">Use the given extension key name to filter for your one! The Extension Management service will inform your script about every extension that is installed, not only your own one. Otherwise, you would execute your script code for every installed extension and this may slow down the installation process depending on how much your code does.</div>
<h2>What&#8217;s next?</h2>
<p>Pretty simple, isn&#8217;t it? Now it&#8217;s time to pimp your TYPO3 extension to remove as much burden as possible from the user! In a second article we will go into more detail how this can save your users day when your extension imports pages and depending TypoScript configuration.</p>
<p>A special thanks goes to <a href="https://twitter.com/benjaminkott">Benjamin Kott</a> for his <a title="TYPO3 bootstrap_package extension" href="http://typo3.org/extensions/repository/view/bootstrap_package">bootstrap_package</a> because it was the first that provided a working example that the signal/slot infrastructure can be used for these kind of use cases.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://aimeos.org/tips/how-to-execute-scripts-after-installing-typo3-extensions/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
