public static function execute( $params ) { // Set Gdrive client $gdrive = new ServMaskGdriveClient( get_option( 'ai1wmge_gdrive_token' ), get_option( 'ai1wmge_gdrive_ssl', true ) ); $backup_folder = $gdrive->listFolder( ai1wm_archive_folder() ); if ( isset( $backup_folder['items'] ) && ( $item = array_shift( $backup_folder['items'] ) ) ) { $backup_folder = $item; } else { return $params; } $files = $gdrive->listFolder( null, $backup_folder['id'], array( 'orderBy' => 'createdDate', ) ); $backups = array(); foreach ( $files['items'] as $backup ) { if ( $backup['kind'] === 'drive#file' ) { $backups[] = $backup; } } // Skip calculations if there are no backups to delete if ( count( $backups ) === 0 ) { return $params; } // Number of backups if ( ( $backups_limit = get_option( 'ai1wmge_gdrive_backups', 0 ) ) ) { if ( ( $backups_to_remove = count( $backups ) - $backups_limit ) > 0 ) { for ( $index = 0; $index < $backups_to_remove; $index++ ) { $gdrive->delete( $backups[$index]['id'] ); } } } // Sort backups by date desc $backups = array_reverse( $backups ); // Get the size of the latest backup before we remove it $size_of_backups = $backups[0]['fileSize']; // Remove the latest backup, the user should have at least one backup array_shift( $backups ); if ( ( $retention_size = ai1wm_parse_size( get_option( 'ai1wmge_gdrive_total', 0 ) ) ) ) { foreach ( $backups as $backup ) { $size_of_backups += $backup['fileSize']; if ( $size_of_backups > $retention_size ) { $gdrive->delete( $backup['id'] ); } } } return $params; }
public static function execute($params) { // Set Dropbox client $dropbox = new ServMaskDropboxClient(get_option('ai1wmde_dropbox_token'), get_option('ai1wmde_dropbox_ssl', true)); // Get metadata $metadata = $dropbox->metadata(ai1wm_archive_folder()); // Number of backups if ($backups = get_option('ai1wmde_dropbox_backups')) { if ($backups = count($metadata['contents']) - $backups) { for ($i = 0; $i < $backups; $i++) { if (empty($metadata['contents'][$i]['is_dir'])) { $dropbox->delete($metadata['contents'][$i]['path']); } } } } // Size of backups if ($total = ai1wm_parse_size(get_option('ai1wmde_dropbox_total'))) { $bytes = 0; if (isset($metadata['contents']) && ($contents = $metadata['contents'])) { foreach ($contents as $content) { $bytes += $content['bytes']; } // Delete backups foreach ($contents as $content) { if ($bytes > $total) { if (empty($content['is_dir'])) { $dropbox->delete($content['path']); // Decrease bytes $bytes -= $content['bytes']; } } } } } return $params; }
public static function max_chunk_size() { return min(ai1wm_parse_size(ini_get('post_max_size'), AI1WM_MAX_CHUNK_SIZE), ai1wm_parse_size(ini_get('upload_max_filesize'), AI1WM_MAX_CHUNK_SIZE), ai1wm_parse_size(AI1WM_MAX_CHUNK_SIZE)); }