View file upload/src/addons/MMO/Hide/Setup.php

File size: 4Kb
<?php

namespace MMO\Hide;

use XF\AddOn\AbstractSetup;
use XF\AddOn\StepRunnerInstallTrait;
use XF\AddOn\StepRunnerUninstallTrait;
use XF\AddOn\StepRunnerUpgradeTrait;

class Setup extends AbstractSetup
{
    use StepRunnerInstallTrait;
    use StepRunnerUpgradeTrait;
    use StepRunnerUninstallTrait;

    public function installStep1()
    {
        $mmo_hide_buttons = [
            'xfCustom_hide',
            'xfCustom_posts',
            'xfCustom_likes',
            'xfCustom_days',
            'xfCustom_trophies',
            'xfCustom_club',
            'xfCustom_groups',
            'xfCustom_reacts',
            'xfCustom_thanks',
            'xfCustom_reply',
            'xfCustom_replythanks',
            'xfCustom_replyandthanks',
            'xfCustom_users',
            'xfCustom_usersid',
            'xfCustom_usersexc',
            'xfCustom_usersidexc'
        ];

        $this->executeUpgradeQuery("
			INSERT INTO xf_editor_dropdown
				(cmd, icon, buttons, display_order, active)
			VALUES
				('mh_hide', 'fa-eye-slash', ?, 10, 1)	
		", [json_encode($mmo_hide_buttons)]);
    }

    public function installStep2()
    {
        $editorToolbarConfig = $this->app->options()->editorToolbarConfig;

        $optionValue = [
            'toolbarButtons'   => null,
            'toolbarButtonsMD' => null,
            'toolbarButtonsSM' => null,
            'toolbarButtonsXS' => null
        ];

        foreach ($editorToolbarConfig AS $type => $toolbar)
        {
            $toolbar = implode('|', $toolbar);
            $toolbar = preg_replace("/(xfInsert)/", '$0|-vs|mh_hide', $toolbar);
            $toolbar = explode('|', $toolbar);
            $optionValue[$type] = $toolbar;
        }

        /** @var \XF\Repository\Option $optionRepo */
        $optionRepo = \XF::repository('XF:Option');
        $optionRepo->updateOption('editorToolbarConfig', $optionValue);

        /** @var \XF\Repository\Editor */
        \XF::repository('XF:Editor')->rebuildEditorDropdownCache();
    }

    public function upgrade2010010Step1()
    {
        $mmo_hide_buttons = [
            'xfCustom_hide',
            'xfCustom_posts',
            'xfCustom_likes',
            'xfCustom_days',
            'xfCustom_trophies',
            'xfCustom_club',
            'xfCustom_groups',
            'xfCustom_reacts',
            'xfCustom_thanks',
            'xfCustom_reply',
            'xfCustom_replythanks',
            'xfCustom_replyandthanks',
            'xfCustom_users',
            'xfCustom_usersid',
            'xfCustom_usersexc',
            'xfCustom_usersidexc'
        ];

        $this->executeUpgradeQuery("
			INSERT INTO xf_editor_dropdown
				(cmd, icon, buttons, display_order, active)
			VALUES
				('mh_hide', 'fa-eye-slash', ?, 10, 1)	
		", [json_encode($mmo_hide_buttons)]);
    }

    public function upgrade2010010Step2()
    {
        $editorToolbarConfig = $this->app->options()->editorToolbarConfig;

        $optionValue = [
            'toolbarButtons'   => null,
            'toolbarButtonsMD' => null,
            'toolbarButtonsSM' => null,
            'toolbarButtonsXS' => null
        ];

        foreach ($editorToolbarConfig AS $type => $toolbar)
        {
            $toolbar = implode('|', $toolbar);
            $toolbar = preg_replace("/(xfInsert)/", '$0|-vs|mh_hide', $toolbar);
            $toolbar = explode('|', $toolbar);
            $optionValue[$type] = $toolbar;
        }

        /** @var \XF\Repository\Option $optionRepo */
        $optionRepo = \XF::repository('XF:Option');
        $optionRepo->updateOption('editorToolbarConfig', $optionValue);

        \XF::repository('XF:Editor')->rebuildEditorDropdownCache();
    }

    public function uninstallStep1()
    {
        $this->query("DELETE FROM xf_editor_dropdown WHERE cmd = ?", ['mh_hide']);
    }

    public function uninstallStep2()
    {
        \XF::repository('XF:Editor')->rebuildEditorDropdownCache();
    }
}