Drush http://drupal8.ovh/en/tags/drush en Execute a drush command programmatically http://drupal8.ovh/en/tutoriels/235/execute-a-drush-command-programmatically <span class="field field--name-title field--type-string field--label-hidden">Execute a drush command programmatically</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to execute a drush command programmatically ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Thu, 09/29/2016 - 15:49</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h3>Methodes:</h3> <p>drush_invoke (For the current site)<br /><code>drush_invoke($command, $arguments = array());</code></p> <p>drush_invoke_process<br /> This creates a new process in a new Drupal instance. There for you must specify the site alias.<br /><code>drush_invoke_process($site_alias_record, $command_name, $commandline_args = array(), $commandline_options = array(), $backend_options = TRUE);</code></p> <h3>Example 1. Enable a Module/Feature and Revert all features.</h3> <p><code>$site = drush_sitealias_get_record('@mysite');<br /> drush_invoke_process($site, 'pm-enable', array("features_dependencies","-y"));<br /> drush_invoke_process($site, 'features-revert-all', array("-y","--force"));</code></p> <p>//OR for the current site:<br /> drush_invoke_process('@self', 'features-revert-all', array("-y","--force"));<br />  </p> <p> </p> <p>Example 2. Run a drush command at  <span lang="en" xml:lang="en" xml:lang="en"><span>the installation of</span> <span>a module. </span></span></p> <p><code>function mymodule_install() {<br />     // clears the 'all' cache for current web site<br />     //Methode 1.<br />     drush_invoke('cache-clear', 'all');<br />     <br />     Or</code></p> <p><code>    //Methode2.<br />     $site = drush_sitealias_get_record('@mysite');<br />     drush_invoke_process($site, 'cache-clear', array('all'));<br /> }</code></p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> <li><a href="/en/tags/drush" hreflang="en">Drush</a></li> <li><a href="/en/tags/drupal-7" hreflang="en">Drupal 7</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/98/useful-drush-commands" hreflang="en">Useful Drush commands</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=235&amp;2=comment&amp;3=comment" token="0f9d0d1b"></drupal-render-placeholder> </section> Thu, 29 Sep 2016 13:49:30 +0000 editor 235 at http://drupal8.ovh Drupal MySQL Database Import and Export via Drush http://drupal8.ovh/en/tutoriels/206/drupal-mysql-database-import-and-export-via-drush <span class="field field--name-title field--type-string field--label-hidden">Drupal MySQL Database Import and Export via Drush</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to Import and Export Drupal MySQL Database via Drush ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Mon, 07/25/2016 - 14:50</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h2>Export Drupal 8 MySQL Database via Drush</h2> <p><code>drush cr<br /> drush sql-dump &gt; /pathto/mysql-dump-drupal8.sql</code></p> <h2>Import Drupal 8 and MySQL Database via Drush</h2> <p><code>drush sql-drop<br /> drush sql-cli<br /> mysql&gt; source /pathto/mysql-dump-drupal8.sql</code></p> <h2>Export Drupal 7 MySQL Database via Drush</h2> <p><code>drush cc all<br /> drush sql-dump &gt; /pathto/mysql-dump-drupal7.sql</code></p> <h2>Import Drupal 7 MySQL Database via Drush (Same as Drupal 8)</h2> <p><code>//Method 1</code><br /><code>drush sql-drop</code><br /><code>drush sql-cli &lt; /pathto/mysql-dump-drupal.sql<br /> //OR : </code><code>drush sqlc &lt; /pathto/mysql-dump-drupal.sql</code><br /> If you have a error message like: "<strong>Access denied; you need the SUPER privilege for this operation</strong>" Try the Method 2</p> <p><code>//Method 2<br /> drush sql-drop<br /> drush sql-cli<br /> mysql&gt; source /pathto/mysql-dump-drupal8.sql</code></p> <p> </p> <h2>Export to a gz compressed file</h2> <p><code>drush sql-dump <strong>| gzip</strong> &gt; mysql-dump-drupal.sql.gz<br /> drush sql-dump --gzip &gt; mysql-dump-drupal.sql.gz</code></p> <h2>Import a GZ compressed file</h2> <p><code>gunzip &lt; mysql-dump-drupal.sql.gz | drush sqlc</code></p> <p> </p> <p>Options (Example)</p> <p><em>drush sql-dump --data-only --gzip --tables-list="node,users"</em></p> <p><em>More : </em>https://drushcommands.com/drush-8x/sql/sql-dump/</p> <p> </p> <h2>Drush shortcuts</h2> <p>drush sql-cli = drush sqlc<br /> drush sql-query = drush sqlq</p> <h2>Drush sql commandes</h2> <p>drush sql-cli        //Open a SQL command-line interface using Drupal's User and Password<br /> drush sql-connect<br /> drush sql-create    //Create a database<br /> drush sql-drop         // Delete All tables of the current database<br /> drush sql-dump         // Export current drupal Database to a file (like mysqldump)<br /> drush sql-query     //Execute a query<br /> drush sql-sanitize    //Run sanitization operations on the current database<br /> drush sql-sync        //Copies the database contents from a source site to a target site. Transfers the database dump via rsync</p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/drupal-7" hreflang="en">Drupal 7</a></li> <li><a href="/en/tags/drush" hreflang="en">Drush</a></li> <li><a href="/en/tags/database" hreflang="en">Database</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/113/mysql-backup-restore-syntax" hreflang="en">Mysql Database Backup / Restore Syntax</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=206&amp;2=comment&amp;3=comment" token="fe929d65"></drupal-render-placeholder> </section> Mon, 25 Jul 2016 12:50:43 +0000 editor 206 at http://drupal8.ovh Cache Clearing and rebuilding methods for Drupal 8 http://drupal8.ovh/en/tutoriels/147/cache-clearing-and-rebuilding-methods-for-drupal-8 <span class="field field--name-title field--type-string field--label-hidden">Cache Clearing and rebuilding methods for Drupal 8</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>What are the methods for clearing or rebuilding Drupal 8 cache, using site url, drush SQL ... ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Wed, 05/25/2016 - 09:55</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h2>Site URL</h2> <p>1. Go to <strong>Administration &gt; Configuration &gt; Development &gt; Performance</strong><br />  (/admin/config/development/performance)<br /> 2. Click on "<strong>Clear all caches</strong>"</p> <h2>Drush</h2> <p><code>drush cache-rebuild<br /> OR<br /> drush cr</code></p> <h2>Programmatically using PHP (From a drupal module)<code> </code></h2> <p><code>db_query("DELETE FROM {cache};");</code><br />  </p> <h2>By SQL / phpMyAdmin interface</h2> <p>Clear all tables that start with cache_ (CAUTION : Do not DELETE tables)<br /> Ex:<br /><code>TRUNCATE cache_config;<br /> TRUNCATE cache_container;<br /> TRUNCATE cache_data;<br /> TRUNCATE cache_default;<br /> TRUNCATE cache_discovery;<br /> TRUNCATE cache_dynamic_page_cache;<br /> TRUNCATE cache_entity;<br /> TRUNCATE cache_menu;<br /> TRUNCATE cache_render;<br /> TRUNCATE cache_toolbar;</code></p> <h2>Run update.php</h2> <p>Running update.php (<code>/update.php</code>) is another way of clearing the cache.<br /> If you cannot login or have no user 1 rights you will need to set in :<br /><code>/sites/default/settings.php<br /> $update_free_access = TRUE;  </code><br /><strong>Do not forget to set this back to FALSE afterwards.</strong></p> <p>...</p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> <li><a href="/en/tags/server" hreflang="en">Server</a></li> <li><a href="/en/tags/drush" hreflang="en">Drush</a></li> <li><a href="/en/tags/cache" hreflang="en">Cache</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/155/drupal-8-tags-based-cache-system" hreflang="en">Drupal 8 Tags based cache system</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=147&amp;2=comment&amp;3=comment" token="e6ed8c80"></drupal-render-placeholder> </section> Wed, 25 May 2016 07:55:33 +0000 editor 147 at http://drupal8.ovh Migrate from Drupal7 to Drupal8 http://drupal8.ovh/en/tutoriels/143/migrate-from-drupal7-to-drupal8 <span class="field field--name-title field--type-string field--label-hidden">Migrate from Drupal7 to Drupal8</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to Migrate from Drupal7 to Drupal8 using drupal migration tool ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Tue, 05/17/2016 - 21:09</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Example (basic)</p> <p><code>drush migrate<span>-</span>upgrade <span>--</span>legacy<span>-</span>db<span>-</span>url<span>=</span>mysql<span>:</span><span>//user:password@server/db --legacy-root=http://mydrupal6or7site.com</span></code></p> <p><span>Migrate UI (Website)</span><br /><code>/upgrade</code></p> <p>Link : https://www.drupal.org/node/2350603</p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> <li><a href="/en/tags/drush" hreflang="en">Drush</a></li> </ul> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=143&amp;2=comment&amp;3=comment" token="0f9895fb"></drupal-render-placeholder> </section> Tue, 17 May 2016 19:09:57 +0000 editor 143 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/143/migrate-from-drupal7-to-drupal8#comments Install and Update Drush on Linux http://drupal8.ovh/en/tutoriels/138/install-and-update-drush-on-linux <span class="field field--name-title field--type-string field--label-hidden">Install and Update Drush on Linux</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>Install and Update Drush on Linux</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Sun, 05/08/2016 - 13:53</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><pre> <code class="sh hljs bash"><span class="hljs-comment"># Download latest stable release using the code below or browse to github.com/drush-ops/drush/releases.</span> php -r <span class="hljs-string">"readfile('http://files.drush.org/drush.phar');"</span> &gt; drush <span class="hljs-comment"># Or use our upcoming release: php -r "readfile('http://files.drush.org/drush-unstable.phar');" &gt; drush</span> <span class="hljs-comment"># Test your install.</span> php drush core-status <span class="hljs-comment"># Make `drush` executable as a command from anywhere. Destination can be anywhere on $PATH.</span> chmod +x drush sudo mv drush /usr/<span class="hljs-built_in">local</span>/bin <span class="hljs-comment"># Optional. Enrich the bash startup file with completion and aliases.</span> drush init</code></pre> <p> </p> <p>Aa a script: (Run sudo a command first, like sudo ls)</p> <pre> <code class="sh hljs bash">php -r <span class="hljs-string">"readfile('http://files.drush.org/drush.phar');"</span> &gt; drush chmod +x drush sudo mv drush /usr/<span class="hljs-built_in">local</span>/bin drush init </code> </pre> <p> </p> <h2>Update drush (or also install)</h2> <p><code class="sh hljs bash">sudo php -r <span class="hljs-string">"readfile('http://files.drush.org/drush.phar');"</span> &gt; /usr/<span class="hljs-built_in">local</span>/bin/drush<br /> chmod +x /usr/<span class="hljs-built_in">local</span>/bin/drush<br /> drush init</code></p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> <li><a href="/en/tags/drush" hreflang="en">Drush</a></li> </ul> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=138&amp;2=comment&amp;3=comment" token="3032ec9f"></drupal-render-placeholder> </section> Sun, 08 May 2016 11:53:52 +0000 editor 138 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/138/install-and-update-drush-on-linux#comments Useful Drush commands http://drupal8.ovh/en/tutoriels/98/useful-drush-commands <span class="field field--name-title field--type-string field--label-hidden">Useful Drush commands</span> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Mon, 01/11/2016 - 16:28</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>To handle drupal with drust, First of all, you must install drush, and execute drush command from your drupal instalation folder.</p> <ul><li>For default or single site instalation, just put on<strong> drupal root folder</strong> (Ex : <code>/var/www/drupal8</code>)</li> <li>For Multi sites, put in to the <strong>site folder</strong> (Ex : <code>/var/www/drupal8/sites/mysite1</code>)</li> </ul><p> </p> <p>First command : Status<br /><code>drush status</code></p> <p>Download and active a module<br /><code>drush en module_name -y</code></p> <p>Clear All Cache<br /> On D7 # <code>drush cc all</code><br /> On D8 # <code>drush cr</code></p> <p>Get a user login url ( Tempory)<br /><code>drush uli<br /> drush uli [user_id]</code></p> <p>Set / Change User password<br /> drush upwd USERNAME --password="The_New_Password"<br /> Example : <code>drush upwd admin --password=admin</code></p> <h3>Set / Get Variable and configuration</h3> <p>Drupal 7<br /> variable-set (vset)<br /> drush vset variable_name value<br /> Example : <code>drush variable-set stage_file_proxy_origin "http://www.drupal8.ovh"</code></p> <p>Drupal 8<br /> config-set<br /> drush config-set config_name field value<br /> Example : <code>drush config-set stage_file_proxy.settings origin 'http://www.drupal8.ovh' -y</code></p> <p> </p> <h2>Install drupal from drush</h2> <p><code>drush dl drupal --drupal-project-rename=example<br /> cd example<br /> drush site-install standard --db-url='mysql://[db_user]:[db_pass]@localhost/[db_name]'<br /> Options<br /> --site-name=Example --account-name=admin --account-pass=adminpassword</code></p> <p>Example 2 : Install drupal 8 using sqlite database<br /><code>drush site-install standard --db-url='sqlite://sites/default/files/.ht.db.sqlite' --site-name=D8 --account-name=admin --account-pass=admin --notify=0</code></p> <h3>Enable few usefull contrib modules.</h3> <p><code>drush en workbench workbench_moderation youtube imce linkit captcha honeypot securelogin pathauto -y<br /> drush en admin_toolbar admin_toolbar_tools -y</code></p> <p>Enable drupal development modules.</p> <p><code>drush en devel kint coffee features features_ui -y</code></p> <p> </p> <h3>Update disabled modules using Drush</h3> <p>The option --check-disabled Check for updates of disabled modules and themes. This allow you to update modules and themes codes even disabled.<br /> Example :<br /><code>drush pm-updatecode --check-disabled<br /> #OR, shortcut :<br /> drush upc --check-disabled</code><br /> NOTE :  To avoid accidentally update and show the list before update, Do not use the option <strong>-y</strong>.</p> <p> </p> <h3>Get Set Variables / State (set-state / get-state)</h3> <p><strong>Put the site in maintenance mode : Put Site Online / Offline</strong><br /><code><span>drush sset system</span><span>.</span><span>maintenance_mode </span><span>1 // To set</span></code><br /><code><span>drush sget system</span><span>.</span><span>maintenance_mode // To check</span></code><br /><code><span>drush sset system</span><span>.</span><span>maintenance_mode </span><span>0 // To Exit maintenance mode</span></code></p> <p><code>(</code>http://drushcommands.com/drush-8x/core/site-install/ for More info<code>)</code></p> <p>Update Database (/update.php)<br /><code>drush updatedb</code></p> <p>http://drushcommands.com/</p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/drupal-7" hreflang="en">Drupal 7</a></li> <li><a href="/en/tags/drush" hreflang="en">Drush</a></li> <li><a href="/en/tags/shell" hreflang="en">Shell</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/138/install-and-update-drush-on-linux" hreflang="en">Install and Update Drush on Linux</a></div> <div class="field__item"><a href="/en/tutoriels/95/install-drush-on-widows" hreflang="en">Install drush on Widows</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=98&amp;2=comment&amp;3=comment" token="f91de8e2"></drupal-render-placeholder> </section> Mon, 11 Jan 2016 15:28:24 +0000 editor 98 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/98/useful-drush-commands#comments Some Features commands (drush) http://drupal8.ovh/en/tutoriels/97/some-features-commands-drush <span class="field field--name-title field--type-string field--label-hidden">Some Features commands (drush)</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to enable a feature using drush command ?<br /> How to revert a feature using drush cli ?<br /> How to revert all features using drush command ?<br /> How to recreate a feature using drush cli (update a feature) ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Mon, 01/11/2016 - 16:25</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Enable a Features<br /><code>drush en feature_name</code></p> <p>Revert a feature<br /><code>drush fr freture_name</code></p> <p>Revert all features<br /><code>drush fra -y</code><br /> #OR Also<br /><code>drush fr-all</code></p> <p>Recreate a Feature (Update a Feature)<br /><code>drush fu freture_name</code></p> <h3>Disable a feature</h3> <p>To disable a feature, visit the Feature administration page (/admin/structure/features), deselect the appropriate checkbox and <strong>Save </strong>settings.<br /><em><strong>CAUTION </strong>: Disabling the feature module is supposed to also disable all the functionality that was defined by it. That is, remove node types that were created by it, etc...</em></p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/shell" hreflang="en">Shell</a></li> <li><a href="/en/tags/drush" hreflang="en">Drush</a></li> <li><a href="/en/tags/features" hreflang="en">Features</a></li> </ul> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=97&amp;2=comment&amp;3=comment" token="21c84e5d"></drupal-render-placeholder> </section> Mon, 11 Jan 2016 15:25:24 +0000 editor 97 at http://drupal8.ovh