示例#1
0
function xoops_module_update_smartsection($module)
{
    // Load SmartDbUpdater from the SmartObject Framework if present
    $smartdbupdater = XOOPS_ROOT_PATH . "/modules/smartsection/class/smartdbupdater.php";
    include_once $smartdbupdater;
    $dbupdater = new SmartobjectDbupdater();
    ob_start();
    echo "<code>" . _SDU_UPDATE_UPDATING_DATABASE . "<br />";
    // Adding partial_view field
    $table = new SmartDbTable('smartsection_items');
    if (!$table->fieldExists('partial_view')) {
        $table->addNewField('partial_view', "varchar(255) NOT NULL default ''");
    } else {
        $table->addAlteredField('partial_view', "varchar(255) NOT NULL default ''");
    }
    if (!$dbupdater->updateTable($table)) {
        /**
         * @todo trap the errors
         */
    }
    unset($table);
    /**
     * Check for items with categoryid=0
     */
    @($smartsection_item_handler = xoops_getmodulehandler('item', 'smartsection'));
    @($smartsection_category_handler = xoops_getmodulehandler('category', 'smartsection'));
    if ($smartsection_item_handler) {
        //find a valid categoryid
        $categoriesObj = $smartsection_category_handler->getCategories(1, 0, 0, 'weight', 'ASC', false);
        if (count($categoriesObj) > 0) {
            $categoryid = $categoriesObj[0]->getVar('categoryid');
            $criteria = new CriteriaCompo();
            $criteria->add(new Criteria('categoryid', 0));
            $smartsection_item_handler->updateAll('categoryid', $categoryid, $criteria);
            echo "&nbsp;&nbsp;Cleaning up items for with categoryid=0<br />";
        }
    }
    // Adding item_tag field in smartsection_items
    $table = new SmartDbTable('smartsection_items');
    if (!$table->fieldExists('item_tag')) {
        $table->addNewField('item_tag', "TEXT NOT NULL");
    }
    if ($table->fieldExists('tags')) {
        $table->addDropedField('tags');
    }
    if (!$dbupdater->updateTable($table)) {
        /**
         * @todo trap the errors
         */
    }
    unset($table);
    echo "</code>";
    $feedback = ob_get_clean();
    if (method_exists($module, "setMessage")) {
        $module->setMessage($feedback);
    } else {
        echo $feedback;
    }
    return true;
}
示例#2
0
function xoops_module_update_smartfaq($module)
{
    // Load SmartDbUpdater from the SmartObject Framework if present
    $smartdbupdater = XOOPS_ROOT_PATH . "/modules/smartobject/class/smartdbupdater.php";
    if (!file_exists($smartdbupdater)) {
        $smartdbupdater = XOOPS_ROOT_PATH . "/modules/smartfaq/class/smartdbupdater.php";
    }
    include_once $smartdbupdater;
    $dbupdater = new SmartobjectDbupdater();
    ob_start();
    echo "<code>" . _SDU_UPDATE_UPDATING_DATABASE . "<br />";
    // Adding partialview field
    $table = new SmartDbTable('smartfaq_faq');
    if (!$table->fieldExists('partialview')) {
        $table->addNewField('partialview', "tinyint(1) NOT NULL default '0'");
    }
    // Changing categoryid type to int(11)
    $table->addAlteredField('categoryid', "int(11) NOT NULL default '0'", false);
    if (!$dbupdater->updateTable($table)) {
        /**
         * @todo trap the errors
         */
    }
    unset($table);
    // Editing smartfaq_categories table
    $table = new SmartDbTable('smartfaq_categories');
    // Changing categoryid type to int(11)
    $table->addAlteredField('categoryid', "int(11) NOT NULL default '0'", false);
    // Changing parentid type to int(11)
    $table->addAlteredField('parentid', "int(11) NOT NULL default '0'", false);
    if (!$dbupdater->updateTable($table)) {
        /**
         * @todo trap the errors
         */
    }
    unset($table);
    // Editing smartfaq_answers table
    $table = new SmartDbTable('smartfaq_answers');
    // Changing categoryid type to int(11)
    $table->addAlteredField('answerid', "int(11) NOT NULL default '0'", false);
    // Changing parentid type to int(11)
    $table->addAlteredField('faqid', "int(11) NOT NULL default '0'", false);
    if (!$dbupdater->updateTable($table)) {
        /**
         * @todo trap the errors
         */
    }
    unset($table);
    /**
     * Check for items with categoryid=0
     */
    include_once XOOPS_ROOT_PATH . "/modules/smartfaq/include/functions.php";
    $smartfaq_faq_handler = $answer_handler =& sf_gethandler('faq');
    $smartfaq_category_handler = $answer_handler =& sf_gethandler('category');
    //find a valid categoryid
    $categoriesObj = $smartfaq_category_handler->getCategories(1, 0, 0, 'weight', 'ASC', false);
    if (count($categoriesObj) > 0) {
        $categoryid = $categoriesObj[0]->getVar('categoryid');
        $criteria = new CriteriaCompo();
        $criteria->add(new Criteria('categoryid', 0));
        $smartfaq_faq_handler->updateAll('categoryid', $categoryid, $criteria);
        echo "&nbsp;&nbsp;Cleaning up questions with categoryid=0<br />";
    }
    echo "</code>";
    $feedback = ob_get_clean();
    if (method_exists($module, "setMessage")) {
        $module->setMessage($feedback);
    } else {
        echo $feedback;
    }
    return true;
}