Code Duplication    Length = 29-31 lines in 2 locations

class/Common/FilesManagement.php 1 location

@@ 179-209 (lines=31) @@
176
     *
177
     * @return bool true on success
178
     */
179
    public static function rrmdir($src)
180
    {
181
        // Only continue if user is a 'global' Admin
182
        if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
183
            return false;
184
        }
185
186
        // If source is not a directory stop processing
187
        if (!is_dir($src)) {
188
            return false;
189
        }
190
191
        $success = true;
192
193
        // Open the source directory to read in files
194
        $iterator = new \DirectoryIterator($src);
195
        foreach ($iterator as $fObj) {
196
            if ($fObj->isFile()) {
197
                $filename = $fObj->getPathname();
198
                $fObj     = null; // clear this iterator object to close the file
199
                if (!unlink($filename)) {
200
                    return false; // couldn't delete the file
201
                }
202
            } elseif (!$fObj->isDot() && $fObj->isDir()) {
203
                // Try recursively on directory
204
                self::rrmdir($fObj->getPathname());
205
            }
206
        }
207
        $iterator = null;   // clear iterator Obj to close file/directory
208
        return rmdir($src); // remove the directory & return results
209
    }
210
211
    /**
212
     * Recursively move files from one directory to another

class/Utility.php 1 location

@@ 147-175 (lines=29) @@
144
     *
145
     * @return bool true on success
146
     */
147
    public static function rrmdir($src)
148
    {
149
        // Only continue if user is a 'global' Admin
150
        if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
151
            return false;
152
        }
153
154
        // If source is not a directory stop processing
155
        if (!is_dir($src)) {
156
            return false;
157
        }
158
159
        // Open the source directory to read in files
160
        $iterator = new \DirectoryIterator($src);
161
        foreach ($iterator as $fObj) {
162
            if ($fObj->isFile()) {
163
                $filename = $fObj->getPathname();
164
                $fObj     = null; // clear this iterator object to close the file
165
                if (!unlink($filename)) {
166
                    return false; // couldn't delete the file
167
                }
168
            } elseif (!$fObj->isDot() && $fObj->isDir()) {
169
                // Try recursively on directory
170
                static::rrmdir($fObj->getPathname());
171
            }
172
        }
173
        $iterator = null;   // clear iterator Obj to close file/directory
174
        return rmdir($src); // remove the directory & return results
175
    }
176
177
    /**
178
     * Recursively move files from one directory to another