| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * You may not change or alter any portion of this comment or credits | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * of supporting developers from this source code or any supporting source code | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * which is considered copyrighted (c) material of the original comment or credit authors. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @package | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @since           2.5.9 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @author          Michael Beck (aka Mamba) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use XoopsModules\Xoopsfaq; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use XoopsModules\Xoopsfaq\Common; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use XoopsModules\Xoopsfaq\Utility; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | require_once dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | require dirname(__DIR__) . '/preloads/autoloader.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | $op = \Xmf\Request::getCmd('op', ''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | $moduleDirName      = basename(dirname(__DIR__)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | $moduleDirNameUpper = mb_strtoupper($moduleDirName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | $helper = Xoopsfaq\Helper::getInstance(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | // Load language files | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | $helper->loadLanguage('common'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | switch ($op) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     case 'load': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         if (\Xmf\Request::hasVar('ok', 'REQUEST') && 1 == $_REQUEST['ok']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             if (!$GLOBALS['xoopsSecurity']->check()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                 redirect_header('../admin/index.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             loadSampleData(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             xoops_cp_header(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             xoops_confirm(['ok' => 1, 'op' => 'load'], 'index.php', sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'ADD_SAMPLEDATA_OK')), constant('CO_' . $moduleDirNameUpper . '_' . 'CONFIRM'), true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             xoops_cp_footer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     case 'save': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         saveSampleData(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | // XMF TableLoad for SAMPLE data | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  | function loadSampleData() | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     global $xoopsConfig; | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |     $moduleDirName      = basename(dirname(__DIR__)); | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     $moduleDirNameUpper = mb_strtoupper($moduleDirName); | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |     $utility      = new Xoopsfaq\Utility(); | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |     $configurator = new Common\Configurator(); | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |     $tables = \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getInfo('tables'); | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |     $language = 'english/'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |     if (is_dir(__DIR__ . '/' . $xoopsConfig['language'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |         $language = $xoopsConfig['language'] . '/'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |     foreach ($tables as $table) { | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |         $tabledata = \Xmf\Yaml::readWrapped($table . '.yml'); | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |         \Xmf\Database\TableLoad::truncateTable($table); | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |         \Xmf\Database\TableLoad::loadTableFromArray($table, $tabledata); | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |     //  ---  COPY test folder files --------------- | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |     if (is_array($configurator->copyTestFolders) && count($configurator->copyTestFolders) > 0) { | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |         //        $file = __DIR__ . '/../testdata/images/'; | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |         foreach (array_keys($configurator->copyTestFolders) as $i) { | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |             $src  = $configurator->copyTestFolders[$i][0]; | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |             $dest = $configurator->copyTestFolders[$i][1]; | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |             $utility::rcopy($src, $dest); | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |     redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'SAMPLEDATA_SUCCESS')); | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | function saveSampleData() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     global $xoopsConfig; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     $moduleDirName      = basename(dirname(__DIR__)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     $moduleDirNameUpper = mb_strtoupper($moduleDirName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     $tables = \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getInfo('tables'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     $languageFolder = __DIR__ . '/' . $xoopsConfig['language']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     if (!file_exists($languageFolder . '/')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         Utility::createFolder($languageFolder . '/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     $exportFolder = $languageFolder . '/Exports-' . date('Y-m-d-H-i-s') . '/'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     Utility::createFolder($exportFolder); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     foreach ($tables as $table) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         \Xmf\Database\TableLoad::saveTableToYamlFile($table, $exportFolder . $table . '.yml'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'SAMPLEDATA_SUCCESS')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | function exportSchema() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     $moduleDirName      = basename(dirname(__DIR__)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     $moduleDirNameUpper = mb_strtoupper($moduleDirName); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         // TODO set exportSchema | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         //        $migrate = new Xoopsfaq\Migrate($moduleDirName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         //        $migrate->saveCurrentSchema(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         //        redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_SUCCESS')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     } catch (\Exception $e) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         exit(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_ERROR')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 125 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 126 |  |  |  | 
            
                        
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.