Magento Module Scripts – Disabling – Inst Schema – Part 02

So, without wasting any time in introduction, we directly jump into the topic Magento Module tutorial for installing scripts. Here in the Part 02, we’ll continue from the previous part we left out.

Let’us do it for you. All you need to buy a basic hosting plan and leave the coding part for us. As we’re providing 100% development and technical support with any Mage cloud Hosting plan. And the service comes in very affordable price as low as USD 9.99 per month.

Tanzia Farin Chy – Aspiration Hosting

Magento Module tutorial – Disabling the module

In the beginning we’ll learn to disable the module.

For completing the task, we need to run the following code:
php bin/magento module:disable Aspiration_Custom

So, instantly it’ll flag as disabled, if check the config.php file.
Let’s use a very interesting command. This command has the ability to execute the module uninstall script. So, it’ll simply delete the full module except the module installed by the composer.

Further, the code is following:
php bin/magento module:uninstall Inchoo_Custom

Magento Module tutorial – Set up classes

In general, there are 6 different setup classes inside the module in Mage 2. Here the classes are following:

Setup/UpgradeSchema
Setup/Recurring
Setup/Uninstall
Setup/InstallData
Setup/InstallSchema
Setup/UpgradeData

Only one class per action is available and no separate setup files & version anymore. For example following is not exist anymore:

upgrade-1.0.0-1.0.1.php
upgrade-1.0.1-1.0.3.php
install-1.0.0.php

For further referral, all above mentioned installer logic is found under the following path:
/setup/src/Magento/Setup/

Magento Module tutorial – Install & Upgrade

Therefore to do install & upgrade, we need Scheme setup scripts. As these setup scripts can change the database Schema. Also according to need they’re able to change or create database tables. In case we’re installing module, we need to execute the: Setup\InstallSchema::install() .


namespace Aspiration\Custom\Setup;
 
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
 
class InstallSchema implements InstallSchemaInterface
{
    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();
 
        $table = $setup->getConnection()->newTable(
            $setup->getTable('inchoo_custom')
        )->addColumn(
            'custom_id',
            \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
            null,
            ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
            'Custom Id'
        )->addColumn(
            'name',
            \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
            255,
            [],
            'Custom Name'
        )->setComment(
            'Custom Table'
        );
        $setup->getConnection()->createTable($table);
 
        $setup->endSetup();
}

Now reading Part 02 | Part 01 | Part 03