<?php
namespace MMO\Hide;
use MMO\Hide\Install\InstallerHelper;
use XF\AddOn\AbstractSetup;
use XF\AddOn\StepRunnerInstallTrait;
use XF\AddOn\StepRunnerUninstallTrait;
use XF\AddOn\StepRunnerUpgradeTrait;
use XF\Db\Exception;
use XF\Repository\EditorRepository;
class Setup extends AbstractSetup
{
use StepRunnerInstallTrait;
use StepRunnerUpgradeTrait;
use StepRunnerUninstallTrait;
use InstallerHelper;
public function installStep1()
{
$hideButtons = [
'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->db()->insert('xf_editor_dropdown', [
'cmd' => 'mh_hide',
'icon' => 'fa-eye-slash',
'buttons' => json_encode($hideButtons),
'display_order' => 10,
'active' => 1
]);
}
/**
* @param array $stateChanges
*/
public function postInstall(array &$stateChanges)
{
// Rebuild Cache
\XF::repository(EditorRepository::class)->rebuildEditorDropdownCache();
if($this->applyDefaultPermissions())
{
$this->app->jobManager()->enqueueUnique(
'permissionRebuild',
'XF:PermissionRebuild',
[],
false
);
}
}
public function upgrade2010010Step1()
{
$hideButtons = [
'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->db()->insert('xf_editor_dropdown', [
'cmd' => 'mh_hide',
'icon' => 'fa-eye-slash',
'buttons' => json_encode($hideButtons),
'display_order' => 10,
'active' => 1
]);
}
public function upgrade2011270Step1()
{
$this->renameStyleProperty('mh_block_type', 'mhBlockType');
$this->renameStyleProperty('mh_block_hidden', 'mhBlockHidden');
$this->renameStyleProperty('mh_block_shown', 'mhBlockShown');
}
/**
* @throws Exception
*/
public function upgrade2020870Step1()
{
$this->renamePermission('forum', 'mh_bypass', 'mh_hide', 'bypassAnyTag');
}
/**
* @throws Exception
*/
public function upgrade2020870Step2()
{
$tags = [
'hide',
'posts',
'likes',
'days',
'trophies',
'club',
'groups',
'thanks',
'reacts',
'reply',
'replythanks',
'replyandthanks',
'users',
'usersid',
'usersexc',
'usersidexc',
];
$ignoreTags = [
'posts',
'likes',
'days',
'trophies',
];
foreach ($tags as $tag)
{
$this->renamePermission('hide', 'useTag' . ucfirst($tag), 'mh_hide', 'useTag' . ucfirst($tag));
$this->renamePermission('hide', 'bypassTag' . ucfirst($tag), 'mh_hide', 'bypassTag' . ucfirst($tag));
if (in_array($tag, $ignoreTags))
{
$this->renamePermission('hide', 'ignoreTag' . ucfirst($tag), 'mh_hide', 'ignoreTag' . ucfirst($tag));
}
}
}
/**
* @param $previousVersion
* @param array $stateChanges
*/
public function postUpgrade($previousVersion, array &$stateChanges)
{
\XF::repository(EditorRepository::class)->rebuildEditorDropdownCache();
}
public function uninstallStep1()
{
$this->db()->delete('xf_editor_dropdown', 'cmd = ?', ['mh_hide']);
}
public function uninstallStep2()
{
\XF::repository(EditorRepository::class)->rebuildEditorDropdownCache();
}
/**
* @param null $previousVersion
* @return bool
*/
protected function applyDefaultPermissions($previousVersion = null): bool
{
$applied = false;
if (!$previousVersion)
{
$tags = [
'hide',
'posts',
'likes',
'days',
'trophies',
'club',
'groups',
'thanks',
'reacts',
'reply',
'replythanks',
'replyandthanks',
'users',
'usersid',
'usersexc',
'usersidexc',
];
foreach ($tags as $tag)
{
$this->applyGlobalPermission('mh_hide', 'useTag' . ucfirst($tag), 'general', 'viewNode');
}
}
return $applied;
}
}