Example #1
0
/**
 * Sets a value for a key in the xhelp_meta table
 *
 * @param string $key
 * @param string $value
 * @return bool TRUE if success, FALSE if failure
 *
 * @access public
 * @author xhelp development team
 */
function ss_SetMeta($key, $value)
{
    $xoopsDB =& Database::getInstance();
    if ($ret = ss_GetMeta($key)) {
        $sql = sprintf("UPDATE %s SET metavalue = %s WHERE metakey = %s", $xoopsDB->prefix('smartsection_meta'), $xoopsDB->quoteString($value), $xoopsDB->quoteString($key));
    } else {
        $sql = sprintf("INSERT INTO %s (metakey, metavalue) VALUES (%s, %s)", $xoopsDB->prefix('smartsection_meta'), $xoopsDB->quoteString($key), $xoopsDB->quoteString($value));
    }
    $ret = $xoopsDB->queryF($sql);
    if (!$ret) {
        return false;
    }
    return true;
}
Example #2
0
function upgradeDB()
{
    global $xoopsModule, $dbupdater;
    $xoopsDB =& Database::getInstance();
    //1. Determine previous release
    //   *** Update this in sql/mysql.sql for each release **
    if (!ss_TableExists('smartsection_meta')) {
        $ver = '0.93';
    } else {
        if (!($ver = ss_GetMeta('version'))) {
            exit(_AM_SS_DB_VERSION_ERR);
        }
    }
    $mid = $xoopsModule->getVar('mid');
    xoops_cp_header();
    ss_adminMenu(-1, _AM_SS_DB_UPDATE_DB);
    echo "<h2>" . _AM_SS_DB_UPDATE_DB . "</h2>";
    $ret = true;
    //2. Do All Upgrades necessary to make current
    //   Break statements are omitted on purpose
    switch ($ver) {
        case '0.93':
            set_time_limit(60);
            printf("<h3>" . _AM_SS_DB_UPDATE_TO . "</h3>", '1.0');
            echo "<ul>";
            // Create table smartsection_meta
            $table = new SmartsectionTable('smartsection_meta');
            $table->setStructure("CREATE TABLE %s (\n        \t\t\t\t\t\tmetakey varchar(50) NOT NULL default '', \n        \t\t\t\t\t\tmetavalue varchar(255) NOT NULL default '', \n        \t\t\t\t\t\tPRIMARY KEY (metakey)) \n        \t\t\t\t\t\tTYPE=MyISAM;");
            $table->setData(sprintf("'version', %s", $xoopsDB->quoteString($ver)));
            $ret = $ret && $dbupdater->updateTable($table);
            unset($table);
            // Add fields in smartsection_categories
            $table = new SmartsectionTable('smartsection_categories');
            $table->addAlteredField('categoryid', "`categoryid` INT( 11 ) NOT NULL AUTO_INCREMENT");
            $table->addAlteredField('parentid', "`parentid` INT( 11 ) DEFAULT '0' NOT NULL");
            $ret = $dbupdater->updateTable($table) && $ret;
            unset($table);
            // Add fields in smartsection_items
            $table = new SmartsectionTable('smartsection_items');
            $table->addAlteredField('categoryid', "`categoryid` INT( 11 ) DEFAULT '0' NOT NULL");
            $table->addAlteredField('itemid', "`itemid` INT( 11 ) NOT NULL AUTO_INCREMENT");
            $ret = $dbupdater->updateTable($table) && $ret;
            unset($table);
            // Add fields in smartsection_files
            $table = new SmartsectionTable('smartsection_files');
            $table->addAlteredField('itemid', "`itemid` INT( 11 ) DEFAULT '0' NOT NULL");
            $table->addAlteredField('fileid', "`fileid` INT( 11 )  NOT NULL AUTO_INCREMENT");
            $ret = $dbupdater->updateTable($table) && $ret;
            unset($table);
            echo "</ul>";
        case '1.0':
            set_time_limit(60);
            printf("<h3>" . _AM_SS_DB_UPDATE_TO . "</h3>", '1.01');
            echo "<ul>";
            // Add fields in smartsection_items
            $table = new SmartsectionTable('smartsection_items');
            $table->addAlteredField('body', "`body` LONGTEXT NOT NULL");
            $ret = $dbupdater->updateTable($table) && $ret;
            unset($table);
            echo "</ul>";
    }
    $newversion = round($xoopsModule->getVar('version') / 100, 2);
    //if successful, update smartsection_meta table with new ver
    if ($ret) {
        printf(_AM_SS_DB_UPDATE_OK, $newversion);
        $ret = ss_SetMeta('version', $newversion);
    } else {
        printf(_AM_SS_DB_UPDATE_ERR, $newversion);
    }
    ss_modFooter();
    xoops_cp_footer();
}