Code Duplication    Length = 57-57 lines in 2 locations

include/action.module.php 1 location

@@ 153-209 (lines=57) @@
150
    $helper->loadLanguage('modinfo');
151
    $helper->loadLanguage('admin');
152
153
    if ($previousVersion < 154) {
154
        //----------------------------------------------------------------
155
        // Remove previous css & images directories since they've been relocated to ./assets
156
        // Also remove uploads directories since they're no longer used
157
        //----------------------------------------------------------------
158
        $old_directories = [
159
            $helper->path('css/'),
160
            $helper->path('js/'),
161
            $helper->path('images/'),
162
            XOOPS_UPLOAD_PATH . '/' . $module->dirname()
163
        ];
164
        foreach ($old_directories as $old_dir) {
165
            $dirInfo = new SplFileInfo($old_dir);
166
            if ($dirInfo->isDir()) {
167
                // The directory exists so delete it
168
                if (false === $utilityClass::rrmdir($old_dir)) {
169
                    $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_DEL_PATH, $old_dir));
170
                    return false;
171
                }
172
            }
173
            unset($dirInfo);
174
        }
175
176
        //-----------------------------------------------------------------------
177
        // Remove ./template/*.html (except index.html) files since they've
178
        // been replaced by *.tpl files
179
        // Note: this will also remove /template/xsitemap_style.html since it's no longer used
180
        //-----------------------------------------------------------------------
181
        $path       = $helper->path('templates/');
182
        $unfiltered = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
183
        $iterator   = new RegexIterator($unfiltered, "/.*\.html/");
184
        foreach ($iterator as $name => $fObj) {
185
            if ($fObj->isFile() && ('index.html' !== $fObj->getFilename())) {
186
                if (false === ($success = unlink($fObj->getPathname()))) {
187
                    $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $fObj->getPathname()));
188
                    return false;
189
                }
190
            }
191
        }
192
193
        //-----------------------------------------------------------------------
194
        // Now remove a some misc files that were renamed or deprecated
195
        //-----------------------------------------------------------------------
196
        $oldFiles = [
197
            $helper->path('include/install.php'),
198
            $helper->path('class/module.php'),
199
            $helper->path('class/menu.php')
200
        ];
201
        foreach ($oldFiles as $file) {
202
            if (is_file($file)) {
203
                if (false === ($delOk = unlink($file))) {
204
                    $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $file));
205
                }
206
                $success = $success && $delOk;
207
            }
208
        }
209
    }
210
    return $success;
211
}
212

include/onupdate.php 1 location

@@ 93-149 (lines=57) @@
90
    $helper->loadLanguage('modinfo');
91
    $helper->loadLanguage('admin');
92
93
    if ($previousVersion < 154) {
94
        //----------------------------------------------------------------
95
        // Remove previous css & images directories since they've been relocated to ./assets
96
        // Also remove uploads directories since they're no longer used
97
        //----------------------------------------------------------------
98
        $old_directories = [
99
            $helper->path('css/'),
100
            $helper->path('js/'),
101
            $helper->path('images/'),
102
            XOOPS_UPLOAD_PATH . '/' . $module->dirname()
103
        ];
104
        foreach ($old_directories as $old_dir) {
105
            $dirInfo = new SplFileInfo($old_dir);
106
            if ($dirInfo->isDir()) {
107
                // The directory exists so delete it
108
                if (false === $utility::rrmdir($old_dir)) {
109
                    $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_DEL_PATH, $old_dir));
110
                    return false;
111
                }
112
            }
113
            unset($dirInfo);
114
        }
115
116
        //-----------------------------------------------------------------------
117
        // Remove ./template/*.html (except index.html) files since they've
118
        // been replaced by *.tpl files
119
        // Note: this will also remove /template/xsitemap_style.html since it's no longer used
120
        //-----------------------------------------------------------------------
121
        $path       = $helper->path('templates/');
122
        $unfiltered = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
123
        $iterator   = new RegexIterator($unfiltered, "/.*\.html/");
124
        foreach ($iterator as $name => $fObj) {
125
            if ($fObj->isFile() && ('index.html' !== $fObj->getFilename())) {
126
                if (false === ($success = unlink($fObj->getPathname()))) {
127
                    $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $fObj->getPathname()));
128
                    return false;
129
                }
130
            }
131
        }
132
133
        //-----------------------------------------------------------------------
134
        // Now remove a some misc files that were renamed or deprecated
135
        //-----------------------------------------------------------------------
136
        $oldFiles = [
137
            $helper->path('include/install.php'),
138
            $helper->path('class/module.php'),
139
            $helper->path('class/menu.php')
140
        ];
141
        foreach ($oldFiles as $file) {
142
            if (is_file($file)) {
143
                if (false === ($delOk = unlink($file))) {
144
                    $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $file));
145
                }
146
                $success = $success && $delOk;
147
            }
148
        }
149
    }
150
    return $success;
151
}
152