PHP Classes

File: htdocs/modules/system/include/update.php

Recommend this page to a friend!
  Packages of Michael Beck   Xoops 2.5   htdocs/modules/system/include/update.php   Download  
File: htdocs/modules/system/include/update.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Xoops 2.5
Modular content management publication system
Author: By
Last change: Merge pull request #1586 from mambax7/feature/Cannot_use_bool_as_array

fix for Cannot use bool as array
Merge branch 'master' of https://github.com/xoops/XoopsCore25 into feature/Cannot_use_bool_as_array
Merge pull request #1577 from ggoffy/master

added groups to member list
updates, Yoda, short arrays, cosmetics
PER-CS formatting
short array
Merge pull request #1239 from Andrew-Staves-Activ/notificationhandler_subscribe_success

Merge branch 'master' into new-version-system
Merge branch 'feature/php8_templates' of https://github.com/mambax7/XoopsCore25 into feature/php8_templates

# Conflicts:
# htdocs/themes/xswatch4/modules/publisher/publisher_item.tpl
Merge xswatch4
Date: 1 month ago
Size: 3,583 bytes
 

Contents

Class file image Download
<?php
/*
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code
 * which is considered copyrighted (c) material of the original comment or credit authors.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

/**
 * @copyright 2000-2025 XOOPS Project (https://xoops.org)
 * @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
 * @package
 * @since
 * @author XOOPS Development Team, Kazumi Ono (AKA onokazu)
 */

/**
 * @param XoopsModule $module
 * @param string|null $prev_version
 *
 * @return bool|null
 */
function xoops_module_update_system(XoopsModule $module, $prev_version = null)
{
   
// irmtfan bug fix: solve templates duplicate issue
   
$ret = null;
    if (
$prev_version < '2.1.1') {
       
$ret = update_system_v211($module);
    }
   
$errors = $module->getErrors();
    if (!empty(
$errors)) {
       
print_r($errors);
    } else {
       
$ret = true;
    }

    return
$ret;
   
// irmtfan bug fix: solve templates duplicate issue
}

// irmtfan bug fix: solve templates duplicate issue
/**
 * @param XoopsModule $module
 *
 * @return bool
 */
function update_system_v211($module)
{
    global
$xoopsDB;
   
$sql = 'SELECT t1.tpl_id FROM ' . $xoopsDB->prefix('tplfile') . ' t1, ' . $xoopsDB->prefix('tplfile') . ' t2 WHERE t1.tpl_refid = t2.tpl_refid AND t1.tpl_module = t2.tpl_module AND t1.tpl_tplset=t2.tpl_tplset AND t1.tpl_file = t2.tpl_file AND t1.tpl_type = t2.tpl_type AND t1.tpl_id > t2.tpl_id';
   
$result = $xoopsDB->query($sql);
    if (!
$xoopsDB->isResultSet($result)) {
        throw new \
RuntimeException(
            \
sprintf(_DB_QUERY_ERROR, $sql) . $xoopsDB->error(),
           
E_USER_ERROR,
        );
    }
   
$tplids = [];
    while (
false !== ($row = $xoopsDB->fetchRow($result))) {
        [
$tplid] = $row;
       
$tplids[] = $tplid;
    }
    if (
count($tplids) > 0) {
       
$tplfile_handler = xoops_getHandler('tplfile');
       
$duplicate_files = $tplfile_handler->getObjects(new Criteria('tpl_id', '(' . implode(',', $tplids) . ')', 'IN'));

        if (
count($duplicate_files) > 0) {
            foreach (
array_keys($duplicate_files) as $i) {
               
$tplfile_handler->delete($duplicate_files[$i]);
            }
        }
    }
   
$sql = 'SHOW INDEX FROM ' . $xoopsDB->prefix('tplfile') . " WHERE KEY_NAME = 'tpl_refid_module_set_file_type'";
    if (!
$result = $xoopsDB->queryF($sql)) {
       
xoops_error($xoopsDB->error() . '<br>' . $sql);

        return
false;
    }
   
$ret = [];
    while (
false !== ($myrow = $xoopsDB->fetchArray($result))) {
       
$ret[] = $myrow;
    }
    if (!empty(
$ret)) {
       
$module->setErrors("'tpl_refid_module_set_file_type' unique index is exist. Note: check 'tplfile' table to be sure this index is UNIQUE because XOOPS CORE need it.");

        return
true;
    }
   
$sql = 'ALTER TABLE ' . $xoopsDB->prefix('tplfile') . ' ADD UNIQUE tpl_refid_module_set_file_type ( tpl_refid, tpl_module, tpl_tplset, tpl_file, tpl_type )';
    if (!
$result = $xoopsDB->exec($sql)) {
       
xoops_error($xoopsDB->error() . '<br>' . $sql);
       
$module->setErrors("'tpl_refid_module_set_file_type' unique index is not added to 'tplfile' table. Warning: do not use XOOPS until you add this unique index.");

        return
false;
    }

    return
true;
}
// irmtfan bug fix: solve templates duplicate issue