public function deleteBackupFiles($lang_folder_path, $days = 0, $dryRun = false, $ext = 'php')
    {
        if ($days < 0) {
            return false;
        }

        try {
            $dir_lang = $this->getLangPath($lang_folder_path);
        } catch (Exception $e) {
            switch ($e->getCode()) {
                //@codeCoverageIgnoreStart
                case self::NO_LANG_FOLDER_FOUND_IN_THESE_PATHS:
                    $this->messageBag->writeError("No lang folder found in these paths:");
                    foreach ($e->getParameter() as $path) {
                        $this->messageBag->writeError("- ".$path);
                    }
                    break;
                //@codeCoverageIgnoreEnd

                case self::NO_LANG_FOLDER_FOUND_IN_YOUR_CUSTOM_PATH:
                    $this->messageBag->writeError('No lang folder found in your custom path: "'.$e->getParameter().'"');
                    break;
            }

            return false;
        }

        $return = true;

        foreach ($this->getBackupFiles($dir_lang) as $file) {
            $fileDate = $this->getBackupFileDate($file, $ext);

            // @codeCoverageIgnoreStart
            // Cannot happen because of glob but safer
            if (is_null($fileDate)) {
                $this->messageBag->writeError('Unable to detect date in file '.$file);
                $return = false;

                continue;
            }
            // @codeCoverageIgnoreEnd

            if ($this->isDateOlderThanDays($fileDate, $days)) {
                if ($dryRun === true) {
                    $deleted = true;
                } else {
                    $deleted = unlink($file);
                }

                if ($deleted === true) {
                    $this->messageBag->writeInfo('Deleting file '.$file);
                } // @codeCoverageIgnoreStart
                else {
                    $this->messageBag->writeError('Unable to delete file '.$file);

                    $return = false;
                }
            } // @codeCoverageIgnoreEnd
            else {
                $this->messageBag->writeInfo('Skip file '.$file.' (not older than '.$days.'day'.Tools::getPlural($days).')');
            }
        }

        return $return;
    }
public function deleteBackupFiles($lang_folder_path, $days = 0, $dryRun = false, $ext = 'php')
    {
        if ($days < 0) {
            return false;
        }

        try {
            $dir_lang = $this->getLangPath($lang_folder_path);
        } catch (Exception $e) {
            switch ($e->getCode()) {
                //@codeCoverageIgnoreStart
                case self::NO_LANG_FOLDER_FOUND_IN_THESE_PATHS:
                    $this->messageBag->writeError("No lang folder found in these paths:");
                    foreach ($e->getParameter() as $path) {
                        $this->messageBag->writeError("- ".$path);
                    }
                    break;
                //@codeCoverageIgnoreEnd

                case self::NO_LANG_FOLDER_FOUND_IN_YOUR_CUSTOM_PATH:
                    $this->messageBag->writeError('No lang folder found in your custom path: "'.$e->getParameter().'"');
                    break;
            }

            return false;
        }

        $return = true;

        foreach ($this->getBackupFiles($dir_lang) as $file) {
            $fileDate = $this->getBackupFileDate($file, $ext);

            // @codeCoverageIgnoreStart
            // Cannot happen because of glob but safer
            if (is_null($fileDate)) {
                $this->messageBag->writeError('Unable to detect date in file '.$file);
                $return = false;

                continue;
            }
            // @codeCoverageIgnoreEnd

            if ($this->isDateOlderThanDays($fileDate, $days)) {
                if ($dryRun === true) {
                    $deleted = true;
                } else {
                    $deleted = unlink($file);
                }

                if ($deleted === true) {
                    $this->messageBag->writeInfo('Deleting file '.$file);
                } // @codeCoverageIgnoreStart
                else {
                    $this->messageBag->writeError('Unable to delete file '.$file);

                    $return = false;
                }
            } // @codeCoverageIgnoreEnd
            else {
                $this->messageBag->writeInfo('Skip file '.$file.' (not older than '.$days.'day'.Tools::getPlural($days).')');
            }
        }

        return $return;
    }
public function deleteBackupFiles ( $ lang_folder_path , $ days = 0 , $ dryRun = false , $ ext = 'php' ) { if ( $ days < 0 ) { return false ; } try { $ dir_lang = $ this -> getLangPath ( $ lang_folder_path ) ; } catch ( Exception $ e ) { switch ( $ e -> getCode ( ) ) { //@codeCoverageIgnoreStart case self :: NO_LANG_FOLDER_FOUND_IN_THESE_PATHS : $ this -> messageBag -> writeError ( "No lang folder found in these paths:" ) ; foreach ( $ e -> getParameter ( ) as $ path ) { $ this -> messageBag -> writeError ( "- " . $ path ) ; } break ; //@codeCoverageIgnoreEnd case self :: NO_LANG_FOLDER_FOUND_IN_YOUR_CUSTOM_PATH : $ this -> messageBag -> writeError ( 'No lang folder found in your custom path: "' . $ e -> getParameter ( ) . '"' ) ; break ; } return false ; } $ return = true ; foreach ( $ this -> getBackupFiles ( $ dir_lang ) as $ file ) { $ fileDate = $ this -> getBackupFileDate ( $ file , $ ext ) ; // @codeCoverageIgnoreStart // Cannot happen because of glob but safer if ( is_null ( $ fileDate ) ) { $ this -> messageBag -> writeError ( 'Unable to detect date in file ' . $ file ) ; $ return = false ; continue ; } // @codeCoverageIgnoreEnd if ( $ this -> isDateOlderThanDays ( $ fileDate , $ days ) ) { if ( $ dryRun === true ) { $ deleted = true ; } else { $ deleted = unlink ( $ file ) ; } if ( $ deleted === true ) { $ this -> messageBag -> writeInfo ( 'Deleting file ' . $ file ) ; } // @codeCoverageIgnoreStart else { $ this -> messageBag -> writeError ( 'Unable to delete file ' . $ file ) ; $ return = false ; } } // @codeCoverageIgnoreEnd else { $ this -> messageBag -> writeInfo ( 'Skip file ' . $ file . ' (not older than ' . $ days . 'day' . Tools :: getPlural ( $ days ) . ')' ) ; } } return $ return ; }
Delete backup files

@param string $lang_folder_path
@param int $days
@param bool|false $dryRun
@param string $ext

@return bool
Delete backup files