Houston, we've got a problem! Drush comes to help

Drush comes to help

One of the main issues with Drupal is that you need often to choose between stable releases and functionalities. By the time I wrote this article Drupal 8 had a lot of functionalities on its core but most of the interesting modules were on alpha or beta releases, and worse enough, sometimes unstabilities can mean you can't uninstall from UI. On these cases we have a tool that makes Drupal a more rounded system: Drush.

Step by step:

Ok, first let us go to the mistake that motivates this article, sometimes wanting to walk in the edge we find out our site out of order. I wanted to handle images as an independent entity so I would be able to upload them once and reuse on a more comfortable way than just attaching on editor. I just read that  Media was meant to be fully revamped so I chose to give a try to it.

So first of all we go for dependencies:

File Entity
Entity Browser
Entity Embed

So we installed modules one by one, but, of course, those modules had dependencies too:

  1. Entity Browser
  2. Entity Embed
  3. Dropzonejs
  4. Embed

And on top of that we found out that we needed to install JavaScript libraries too:

  1. dropzone.js
  2. imagesloaded
  3. masonry

Installing modules:

I know someone can think "this is handled by composer" and yes, you might be right if you are using composer but this is not the step by step approach I'm following on this blog, this is intended to be a from-zero-to-hero blog not a hero-fuck-the-zero blog. I will going to paste all the needed files I installed one after another but I recommend doing the installation one after another  and not all in a row to be able to limit the source of failures:

wget https://ftp.drupal.org/files/projects/file_entity-8.x-2.0-beta3.tar.gz
tar -zxvf file_entity-8.x-2.0-beta3.tar.gz
rm -rf file_entity-8.x-2.0-beta3.tar.gz
wget https://ftp.drupal.org/files/projects/entity_browser-8.x-1.0-beta2.tar.gz
tar -zxvf entity_browser-8.x-1.0-beta2.tar.gz
rm entity_browser-8.x-1.0-beta2.tar.gz
wget https://ftp.drupal.org/files/projects/entity_embed-8.x-1.0-beta2.tar.gz
rm entity_embed-8.x-1.0-beta2.tar.gz
wget https://ftp.drupal.org/files/projects/entity_embed-8.x-1.0-beta2.tar.gz
tar -zxvf entity_embed-8.x-1.0-beta2.tar.gz
rm entity_embed-8.x-1.0-beta2.tar.gz
wget https://ftp.drupal.org/files/projects/embed-8.x-1.0-rc3.tar.gz
tar -zxvf embed-8.x-1.0-rc3.tar.gz
rm embed-8.x-1.0-rc3.tar.gz
wget https://ftp.drupal.org/files/projects/media-8.x-1.x-dev.tar.gz
tar -zxvf media-8.x-1.x-dev.tar.gz
rm media-8.x-1.x-dev.tar.gz
wget https://ftp.drupal.org/files/projects/file_browser-8.x-1.0-alpha3.tar.gz
tar -zxvf file_browser-8.x-1.0-alpha3.tar.gz
rm file_browser-8.x-1.0-alpha3.tar.gz
wget https://ftp.drupal.org/files/projects/dropzonejs-8.x-1.0-alpha3.tar.gz
tar -zxvf dropzonejs-8.x-1.0-alpha3.tar.gz
rm dropzonejs-8.x-1.0-alpha3.tar.gz

Installing libraries:

Once we start installing modules it will ask for libraries once we get to  dropzone same with file browser, we need to do this in order to have libraries availables for Drupal.

mkdir libraries
cd libraries/
wget https://github.com/enyo/dropzone/archive/master.zip
unzip master.zip
rm master.zip
mv dropzone-master/ dropzone
rm -rf dropzone/test/
wget https://github.com/desandro/imagesloaded/archive/master.zip
unzip master.zip
mv imagesloaded-master/ imagesloaded/
cd imagesloaded/
ls -la
rm -rf test/
rm -rf sandbox/
rm master.zip
wget https://github.com/desandro/masonry/archive/v4.1.1.tar.gz
tar -zxvf v4.1.1.tar.gz
mv masonry-4.1.1/ masonry
cd masonry/
rm -rf test
rm -rf sandbox/
ls -la
rm -rf .github/
rm v4.1.1.tar.gz

As you can see, test and sandbox directories should be deleted to avoid security problems.

With all activated, we have a file content, a block to load files and an embedded button to attach file-browser on editor, this promises to be nice when it's working but today... well, mixing dev and alpha versions is like added Glycerin to Nitrous Oxide so it's likely to explode, this was my case so now it's time to rollback...

The problem:

And here it comes the problem... there was no way to uninstall them, supposedly this happens when there are dependencies, let it be other modules or structure or content or blocks, so the first step was removing all related entities and content... no luck.

Without anything having a straight dependence with entity-browser, or at least nothing I could find out, and there was no way to remove this and we end up with a site full of useless modules. According to this article, this can be a "feature" to avoid leaving crap behind you, but this is something that can be painful if you are a "playful moron" or a "developer".

And now what?

Ok, there is no need to delete your Drupal and start over, you can always remove modules "like a beast" (it is feasible but not recommended) or you can use Drush, what the hell is drush? well, drush is like that pal that comes to your place with chips and beers to play when you are bored on a rainy afternoon. Drush is a shell command that allows you to manage your Drupal site from a command line, it's the swiss knife we all need to have with us when we go to Drupal forest to explore the woods.

Installing Drush

Installation procedure on Drush 8 can't be easier (Drush is sadly being replaced by composer from Drush 9) just aim and fire:

php -r "readfile('https://s3.amazonaws.com/files.drush.org/drush.phar');" > drush
php drush core-status
chmod +x drush
sudo mv drush /usr/local/bin
# this last step is optative but recommended, it's used to integrate drush into shell
drush init

Once drush is installed (you can use Drush 8 without composer or you will need composer if you plan to use Drush 9), we have two options, we can call drush from our drupal root and this will find the configuration to be applied, or we can make it available to all users, the latter is recommended but won't be done in this article.

Now with our brand new Drush we can spread justice like Dirty Harry, but with the right order to avoid problems with dependencies:

cd /var/www/drupal/
drush
drush pmu file_browser_example
drush pmu file_browser
drush pmu dropzonejs_eb_widget
drush pmu entity_browser
drush pmu dropzonejs
drush pmu entity_embed
drush pmu file_entity
drush pmu embed

Now our place is clean and tidy, we should remove libraries too although it's not mandatory.

Here you can find a nice presentation about Drush.

Here you can find the reference sheet of Drush.