Code Duplication    Length = 28-31 lines in 2 locations

class/common/traitfilesmgmt.php 2 locations

@@ 171-201 (lines=31) @@
168
     *
169
     * @return bool true on success
170
     */
171
    public static function rmove($src, $dest)
172
    {
173
        // Only continue if user is a 'global' Admin
174
        if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
175
            return false;
176
        }
177
178
        // If source is not a directory stop processing
179
        if (!is_dir($src)) {
180
            return false;
181
        }
182
183
        // If the destination directory does not exist and could not be created stop processing
184
        if (!is_dir($dest) && !mkdir($dest, 0755)) {
185
            return false;
186
        }
187
188
        // Open the source directory to read in files
189
        $iterator = new DirectoryIterator($src);
190
        foreach ($iterator as $fObj) {
191
            if ($fObj->isFile()) {
192
                rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
193
            } elseif (!$fObj->isDot() && $fObj->isDir()) {
194
                // Try recursively on directory
195
                self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
196
                //                rmdir($fObj->getPath()); // now delete the directory
197
            }
198
        }
199
        $iterator = null;   // clear iterator Obj to close file/directory
200
        return rmdir($src); // remove the directory & return results
201
    }
202
203
    /**
204
     * Recursively copy directories and files from one directory to another
@@ 214-241 (lines=28) @@
211
     *
212
     * @return bool true on success
213
     */
214
    public static function rcopy($src, $dest)
215
    {
216
        // Only continue if user is a 'global' Admin
217
        if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
218
            return false;
219
        }
220
221
        // If source is not a directory stop processing
222
        if (!is_dir($src)) {
223
            return false;
224
        }
225
226
        // If the destination directory does not exist and could not be created stop processing
227
        if (!is_dir($dest) && !mkdir($dest, 0755)) {
228
            return false;
229
        }
230
231
        // Open the source directory to read in files
232
        $iterator = new DirectoryIterator($src);
233
        foreach ($iterator as $fObj) {
234
            if ($fObj->isFile()) {
235
                copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
236
            } elseif (!$fObj->isDot() && $fObj->isDir()) {
237
                self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
238
            }
239
        }
240
        return true;
241
    }
242
}
243