Ip\Internal\Plugins\Model::removePlugin PHP Метод

removePlugin() публичный статический Метод

public static removePlugin ( $pluginName )
    public static function removePlugin($pluginName)
    {
        $activePlugins = self::getActivePluginNames();
        if (in_array($pluginName, $activePlugins)) {
            throw new \Ip\Exception\Plugin\Setup('Please deactivate the plugin before removing it.');
        }
        $pluginRecord = self::getPluginRecord($pluginName);
        if ($pluginRecord) {
            $version = $pluginRecord['version'];
        } else {
            $version = null;
        }
        self::executeSqlIfExists(ipFile('Plugin/' . esc($pluginName) . '/Setup/remove.sql'));
        $workerClass = 'Plugin\\' . $pluginName . '\\Setup\\Worker';
        if (method_exists($workerClass, 'remove')) {
            $worker = new $workerClass($version);
            $worker->remove();
        }
        $dbh = ipDb()->getConnection();
        $sql = '
        DELETE FROM
            ' . ipTable('plugin') . '
        WHERE
            `name` = :pluginName
        ';
        $params = array('pluginName' => $pluginName);
        $q = $dbh->prepare($sql);
        $q->execute($params);
        $pluginDir = ipFile('Plugin/' . $pluginName);
        try {
            $result = Helper::removeDir($pluginDir);
            if (!$result) {
                throw new \Ip\Exception\Plugin\Setup('Can\'t remove folder ' . esc($pluginDir));
            }
        } catch (\Ip\PhpException $e) {
            throw new \Ip\Exception\Plugin\Setup('Can\'t remove folder ' . esc($pluginDir));
        }
        ipLog()->info('Ip.pluginRemoved: {plugin} {version} removed.', array('plugin' => $pluginName, 'version' => $version));
        ipEvent('ipPluginRemoved', array('name' => $pluginName, 'version' => $version));
    }