Example #1
0
function com_uninstall()
{
    jimport('joomla.version');
    $version = new JVersion();
    if (version_compare($version->getShortVersion(), '1.6', '<')) {
        $db = JFactory::getDBO();
        $db->setQuery("Delete From #__components Where `admin_menu_link` Like 'option=com_contentbuilder%'");
        $db->query();
        $plugins = cbgetPlugins();
        $installer = new JInstaller();
        foreach ($plugins as $folder => $subplugs) {
            foreach ($subplugs as $plugin) {
                $db->setQuery('SELECT `id` FROM #__plugins WHERE `element` = "' . $plugin . '" AND `folder` = "' . $folder . '"');
                $id = $db->loadResult();
                if ($id) {
                    $installer->uninstall('plugin', $id, 1);
                }
            }
        }
    }
}
Example #2
0
function com_install()
{
    jimport('joomla.version');
    $version = new JVersion();
    if (version_compare($version->getShortVersion(), '1.6', '<')) {
        contentbuilder_install_db();
        $tables = JFactory::getDBO()->getTableFields(JFactory::getDBO()->getTableList());
        // articles updates
        if (isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_articles'])) {
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_articles']['type'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_articles` ADD `type` VARCHAR( 55 ) NOT NULL DEFAULT '' AFTER `article_id` , ADD `reference_id` VARCHAR( 100 ) NOT NULL DEFAULT '' AFTER `type` ");
                JFactory::getDBO()->query();
            }
        }
        // storages updates
        if (isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_storages'])) {
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_storages']['bytable'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_storages` ADD `bytable` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `title`  ");
                JFactory::getDBO()->query();
            }
        }
        // forms updates
        if (isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms'])) {
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['initial_order_dir'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `initial_order_dir` VARCHAR( 4 ) NOT NULL DEFAULT 'desc' AFTER `initial_sort_order` ");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['list_rating'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `list_rating` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `theme_plugin` ");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['rating_slots'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `rating_slots` TINYINT( 1 ) NOT NULL DEFAULT '5' AFTER `list_rating`  ");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['rand_date_update'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `rand_date_update` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `rating_slots` , ADD INDEX ( `rand_date_update` )   ");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['rand_update'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `rand_update` INT NOT NULL DEFAULT '86400' AFTER `rand_date_update` ");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['article_record_impact_publish'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `article_record_impact_publish` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `rand_update` , ADD `article_record_impact_language` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `article_record_impact_publish` ");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['allow_external_filter'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `allow_external_filter` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `article_record_impact_language` ");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['show_filter'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `show_filter` TINYINT( 1 ) NOT NULL DEFAULT '1' AFTER `allow_external_filter`  ");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['show_records_per_page'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `show_records_per_page` TINYINT( 1 ) NOT NULL DEFAULT '1' AFTER `show_filter`  ");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['initial_list_limit'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `initial_list_limit` TINYINT NOT NULL DEFAULT '20' AFTER `show_records_per_page` ");
                JFactory::getDBO()->query();
                // exceptionally here
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_articles` ADD INDEX ( `type` )");
                JFactory::getDBO()->query();
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` ADD INDEX ( `type` )");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['tag'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `tag` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `name`, ADD INDEX ( `tag` ) ");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['save_button_title'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `save_button_title` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `initial_list_limit` , ADD `apply_button_title` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `save_button_title` ");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['filter_exact_match'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `filter_exact_match` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `save_button_title`");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_forms']['initial_sort_order2'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` ADD `initial_sort_order2` VARCHAR( 255 ) NOT NULL DEFAULT '-1' AFTER `initial_sort_order` , ADD `initial_sort_order3` VARCHAR( 255 ) NOT NULL DEFAULT '-1' AFTER `initial_sort_order2` ");
                JFactory::getDBO()->query();
            }
        }
        // elements updates
        if (isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_elements'])) {
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_elements']['order_type'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_elements` ADD `order_type` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `published` ");
                JFactory::getDBO()->query();
            }
        }
        // records updates
        if (isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_records'])) {
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_records']['rating_sum'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` ADD `rating_sum` INT( 10 ) NOT NULL DEFAULT '0' AFTER `is_future` ");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_records']['rating_count'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` ADD `rating_count` INT( 10 ) NOT NULL DEFAULT '0' AFTER `rating_sum` ");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_records']['lastip'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` ADD `lastip` VARCHAR( 50 ) NOT NULL DEFAULT '' AFTER `rating_count`  ");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_records']['type'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` ADD `type` VARCHAR( 255 ) NOT NULL DEFAULT '' AFTER `id` ");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_records']['session_id'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` ADD `session_id` VARCHAR( 32 ) NOT NULL DEFAULT '' AFTER `lastip` ");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_records']['rand_date'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` ADD `rand_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `published` , ADD INDEX ( `rand_date` ) ");
                JFactory::getDBO()->query();
            }
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_records']['metadesc'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` ADD `metakey` TEXT NOT NULL ,ADD `metadesc` TEXT NOT NULL ,ADD `robots` VARCHAR( 255 ) NOT NULL DEFAULT '',ADD `author` VARCHAR( 255 ) NOT NULL DEFAULT '',ADD `rights` VARCHAR( 255 ) NOT NULL DEFAULT '',ADD `xreference` VARCHAR( 255 ) NOT NULL DEFAULT ''");
                JFactory::getDBO()->query();
            }
        }
        // element access
        if (isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_resource_access'])) {
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_resource_access']['type'])) {
                // sorry but we have to truncate the table
                JFactory::getDBO()->setQuery("TRUNCATE TABLE `#__contentbuilder_resource_access`");
                JFactory::getDBO()->query();
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_resource_access` ADD `type` VARCHAR( 100 ) NOT NULL DEFAULT '' FIRST  ");
                JFactory::getDBO()->query();
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_resource_access` DROP INDEX `form_id` ");
                JFactory::getDBO()->query();
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_resource_access` ADD UNIQUE ( `type` , `element_id` , `resource_id` )");
                JFactory::getDBO()->query();
            }
        }
        // switching to ints for record_id and reference_id
        if (isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_verifications'])) {
            if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_verifications']['create_invoice'])) {
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_verifications` ADD `create_invoice` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `verification_data` ");
                JFactory::getDBO()->query();
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_articles` CHANGE `reference_id` `reference_id` INT NOT NULL DEFAULT '0', CHANGE `record_id` `record_id` BIGINT NOT NULL DEFAULT '0'");
                JFactory::getDBO()->query();
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_elements` CHANGE `reference_id` `reference_id` INT NOT NULL DEFAULT '0'");
                JFactory::getDBO()->query();
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_forms` CHANGE `reference_id` `reference_id` INT NOT NULL DEFAULT '0'");
                JFactory::getDBO()->query();
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_list_records` CHANGE `record_id` `record_id` BIGINT NOT NULL DEFAULT '0', CHANGE `reference_id` `reference_id` INT NOT NULL DEFAULT '0'");
                JFactory::getDBO()->query();
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_rating_cache` CHANGE `record_id` `record_id` BIGINT NOT NULL DEFAULT '0'");
                JFactory::getDBO()->query();
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_registered_users` CHANGE `record_id` `record_id` BIGINT NOT NULL DEFAULT '0'");
                JFactory::getDBO()->query();
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_records` CHANGE `record_id` `record_id` BIGINT NOT NULL DEFAULT '0', CHANGE `reference_id` `reference_id` INT NOT NULL DEFAULT '0'");
                JFactory::getDBO()->query();
                JFactory::getDBO()->setQuery("ALTER TABLE `#__contentbuilder_resource_access` CHANGE `element_id` `element_id` INT NOT NULL DEFAULT '0'");
                JFactory::getDBO()->query();
            }
        }
        // rating cache
        if (!isset($tables[JFactory::getDBO()->getPrefix() . 'contentbuilder_rating_cache'])) {
            JFactory::getDBO()->setQuery("CREATE TABLE `#__contentbuilder_rating_cache` (\n              `record_id` varchar(255) NOT NULL DEFAULT '',\n              `form_id` int(11) NOT NULL DEFAULT '0',\n              `ip` varchar(50) NOT NULL DEFAULT '',\n              `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',\n              KEY `record_id` (`record_id`,`form_id`,`ip`),\n              KEY `date` (`date`)\n            ) ;");
            JFactory::getDBO()->query();
        }
        // trying to ease the 0.9 update pain
        $db = JFactory::getDBO();
        $db->setQuery("Select `type`,`reference_id` From #__contentbuilder_forms");
        $typeref = $db->loadAssocList();
        foreach ($typeref as $tr) {
            $db->setQuery("Update #__contentbuilder_records Set `type` = " . $db->Quote($tr['type']) . " Where `type` = '' And reference_id = " . $db->Quote($tr['reference_id']));
            $db->query();
        }
        if (!version_compare(PHP_VERSION, '5.2.0', '>=')) {
            echo '<b style="color:red">WARNING: YOU ARE RUNNING PHP VERSION "' . PHP_VERSION . '". ContentBuilder WON\'T WORK WITH THIS VERSION. PLEASE UPGRADE TO AT LEAST PHP 5.2.0, SORRY BUT YOU BETTER UNINSTALL THIS COMPONENT NOW!</b>';
        }
        $db = JFactory::getDBO();
        jimport('joomla.filesystem.file');
        jimport('joomla.filesystem.folder');
        // cleaning up leftovers (additional list view overrides, that didn't work with J! 1.7
        for ($a = 1; $a <= 5; $a++) {
            if (JFile::exists(JPATH_SITE . DS . 'components' . DS . 'com_contentbuilder' . DS . 'views' . DS . 'list' . DS . 'tmpl' . DS . 'custom' . $a . '.php')) {
                JFile::delete(JPATH_SITE . DS . 'components' . DS . 'com_contentbuilder' . DS . 'views' . DS . 'list' . DS . 'tmpl' . DS . 'custom' . $a . '.php');
            }
            if (JFile::exists(JPATH_SITE . DS . 'components' . DS . 'com_contentbuilder' . DS . 'views' . DS . 'list' . DS . 'tmpl' . DS . 'custom' . $a . '.xml')) {
                JFile::delete(JPATH_SITE . DS . 'components' . DS . 'com_contentbuilder' . DS . 'views' . DS . 'list' . DS . 'tmpl' . DS . 'custom' . $a . '.xml');
            }
        }
        $plugins = cbgetPlugins();
        $base_path = JPATH_SITE . DS . 'administrator' . DS . 'components' . DS . 'com_contentbuilder' . DS . 'plugins';
        $folders = JFolder::folders($base_path);
        $installer = new JInstaller();
        foreach ($folders as $folder) {
            echo 'Installing plugin <b>' . $folder . '</b><br/>';
            $success = $installer->install($base_path . DS . $folder);
            if (!$success) {
                echo 'Install failed for plugin <b>' . $folder . '</b><br/>';
            }
            echo '<hr/>';
        }
        foreach ($plugins as $folder => $subplugs) {
            foreach ($subplugs as $plugin) {
                $db->setQuery('Update #__plugins Set `published` = 1 WHERE `element` = "' . $plugin . '" AND `folder` = "' . $folder . '"');
                $db->query();
                echo 'Published plugin ' . $plugin . '<hr/>';
            }
        }
    }
}