| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: |
|
| 11: |
|
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: |
|
| 19: |
|
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: |
|
| 26: | function xoops_module_update_system(XoopsModule $module, $prev_version = null)
|
| 27: | {
|
| 28: |
|
| 29: | $ret = null;
|
| 30: | if ($prev_version < '2.1.1') {
|
| 31: | $ret = update_system_v211($module);
|
| 32: | }
|
| 33: | $errors = $module->getErrors();
|
| 34: | if (!empty($errors)) {
|
| 35: | print_r($errors);
|
| 36: | } else {
|
| 37: | $ret = true;
|
| 38: | }
|
| 39: |
|
| 40: | return $ret;
|
| 41: |
|
| 42: | }
|
| 43: |
|
| 44: |
|
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: |
|
| 50: | function update_system_v211($module)
|
| 51: | {
|
| 52: | global $xoopsDB;
|
| 53: | $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';
|
| 54: | $result = $xoopsDB->query($sql);
|
| 55: | if (!$xoopsDB->isResultSet($result)) {
|
| 56: | throw new \RuntimeException(
|
| 57: | \sprintf(_DB_QUERY_ERROR, $sql) . $xoopsDB->error(), E_USER_ERROR
|
| 58: | );
|
| 59: | }
|
| 60: | $tplids = array();
|
| 61: | while (false !== (list($tplid) = $xoopsDB->fetchRow($result))) {
|
| 62: | $tplids[] = $tplid;
|
| 63: | }
|
| 64: | if (count($tplids) > 0) {
|
| 65: | $tplfile_handler = xoops_getHandler('tplfile');
|
| 66: | $duplicate_files = $tplfile_handler->getObjects(new Criteria('tpl_id', '(' . implode(',', $tplids) . ')', 'IN'));
|
| 67: |
|
| 68: | if (count($duplicate_files) > 0) {
|
| 69: | foreach (array_keys($duplicate_files) as $i) {
|
| 70: | $tplfile_handler->delete($duplicate_files[$i]);
|
| 71: | }
|
| 72: | }
|
| 73: | }
|
| 74: | $sql = 'SHOW INDEX FROM ' . $xoopsDB->prefix('tplfile') . " WHERE KEY_NAME = 'tpl_refid_module_set_file_type'";
|
| 75: | if (!$result = $xoopsDB->queryF($sql)) {
|
| 76: | xoops_error($xoopsDB->error() . '<br>' . $sql);
|
| 77: |
|
| 78: | return false;
|
| 79: | }
|
| 80: | $ret = array();
|
| 81: | while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
|
| 82: | $ret[] = $myrow;
|
| 83: | }
|
| 84: | if (!empty($ret)) {
|
| 85: | $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.");
|
| 86: |
|
| 87: | return true;
|
| 88: | }
|
| 89: | $sql = 'ALTER TABLE ' . $xoopsDB->prefix('tplfile') . ' ADD UNIQUE tpl_refid_module_set_file_type ( tpl_refid, tpl_module, tpl_tplset, tpl_file, tpl_type )';
|
| 90: | if (!$result = $xoopsDB->queryF($sql)) {
|
| 91: | xoops_error($xoopsDB->error() . '<br>' . $sql);
|
| 92: | $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.");
|
| 93: |
|
| 94: | return false;
|
| 95: | }
|
| 96: |
|
| 97: | return true;
|
| 98: | }
|
| 99: |
|
| 100: | |