Exemplo n.º 1
0
	/**
	 * Get all backup files
	 *
	 * @return array
	 */
	public function get_files() {
		$backups  = array();

		try {
			$iterator = new RegexIterator(
				new DirectoryIterator( AI1WM_BACKUPS_PATH ),
				'/^(.+)-(\d+)-(\d+)-(\d+)\.wpress$/',
				RegexIterator::GET_MATCH
			);

			foreach ( $iterator as $item ) {
				try {
					$backup = new Ai1wm_File;
					$backup->setFile( $item[0] );
					$backup->setName( $item[1] );
					$backup->setSize( $iterator->getSize() );
					$backup->setCreatedAt( strtotime( "{$item[2]} {$item[3]}" ) );

					// Add backup file
					$backups[] = $backup;
				} catch ( Exception $e ) {
					// Log the error
					Ai1wm_Log::error( 'Exception while listing backup file: ' . $e->getMessage() );
				}
			}
		} catch ( Exception $e ) {
			$backups = array();
		}

		// Sort backups by most recent first
		usort( $backups, array( $this, 'compare' ) );

		return $backups;
	}