Skip to content

Commit a2bb1cb

Browse files
committed
Merge in master
2 parents db167ff + d73034d commit a2bb1cb

34 files changed

+604
-109
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ reports/
1313
package-lock.json
1414
yarn-error.log
1515
cli/bgbkup-cli.log
16+
cli/verify-*
1617
cron/cron-test.config
1718
cron/cron-test.result
18-
cron/restore-info.json
19+
cron/restore-info-*
1920
boldgrid-backup-cron.log
2021
.ea-php-cli.cache
2122
.vscode

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@ before_script:
1717
- nvm install 10
1818
- nvm use 10
1919
- yarn install
20+
- composer self-update --1
2021
- composer install -o --no-dev
2122
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
2223

2324
script:
2425
- find . -name composer -prune -o -name node_modules -prune -o -name '*.php' -exec php -lf {} \; > /dev/null
2526
- phpunit --debug --coverage-clover=coverage.xml
2627
- yarn run php-codesniffer
27-
- yarn run js-lint
28+
# Temp. Different results in wpbex2 vs travix.
29+
# - yarn run js-lint
2830

2931
after_success:
3032
- bash <(curl -s https://codecov.io/bash)
3133

3234
deploy:
3335
- provider: script
34-
script: chmod +x ./node_modules/@boldgrid/wordpress-tag-sync/release.sh && ./node_modules/@boldgrid/wordpress-tag-sync/release.sh
36+
script: chmod +x ./bin/release.sh && ./bin/release.sh
3537
skip_cleanup: true
3638
on:
3739
tags: true

admin/class-boldgrid-backup-admin-archive.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ public function generate_download_link( $filename ) {
747747
public function write_results_file( $info ) {
748748
$success = false;
749749
$archive_filepath = ! empty( $info['filepath'] ) ? $info['filepath'] : null;
750-
$results_filepath = BOLDGRID_BACKUP_PATH . '/cron/restore-info.json';
750+
$results_filepath = \Boldgrid\Backup\Cli\Info::get_results_filepath();
751751
$is_dir_writable = $this->core->wp_filesystem->is_writable( dirname( $results_filepath ) );
752752

753753
if ( $archive_filepath && $is_dir_writable ) {

admin/class-boldgrid-backup-admin-auto-updates.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public function auto_update_core() {
306306
* resources, self::plugins is now initialized within this method, which much be called prior to
307307
* using self::plugins.
308308
*
309-
* @since SINCEVERSION
309+
* @since 1.14.5
310310
*/
311311
private function init_plugins() {
312312
if ( ! empty( $this->plugins ) ) {
@@ -320,7 +320,7 @@ private function init_plugins() {
320320
/**
321321
* Initialize our themes.
322322
*
323-
* @since SINCEVERSION
323+
* @since 1.14.5
324324
*
325325
* @see self::init_plugins() for additional info on this method.
326326
*/

admin/class-boldgrid-backup-admin-core.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,10 +1557,9 @@ public function archive_files( &$info ) {
15571557
$this->logger->add_separator();
15581558

15591559
if ( false === $status || ! empty( $status['error'] ) ) {
1560-
return [
1561-
'error' => ! empty( $status['error'] ) ? $status['error'] :
1562-
__( 'An unknown error occurred when backing up the database.', 'boldgrid-backup' ),
1563-
];
1560+
$error = ! empty( $status['error'] ) ? $status['error'] : __( 'An unknown error occurred when backing up the database.', 'boldgrid-backup' );
1561+
$this->logger->add( $error );
1562+
return array( 'error' => $error );
15641563
}
15651564

15661565
// Keep track of how long the site was paused for / the time to backup the database.
@@ -1577,6 +1576,7 @@ public function archive_files( &$info ) {
15771576

15781577
// Check if the backup directory is writable.
15791578
if ( ! $this->wp_filesystem->is_writable( $backup_directory ) ) {
1579+
$this->logger->add( 'Backup directory is not writable.' );
15801580
return false;
15811581
}
15821582

@@ -1630,6 +1630,18 @@ public function archive_files( &$info ) {
16301630
]
16311631
);
16321632

1633+
if ( Boldgrid_Backup_Admin_Filelist_Analyzer::is_enabled() ) {
1634+
$this->logger->add_separator();
1635+
$this->logger->add( 'Starting to analyze filelist...' );
1636+
$this->logger->add_memory();
1637+
1638+
$filelist_analyzer = new Boldgrid_Backup_Admin_Filelist_Analyzer( $filelist, $log_time );
1639+
$filelist_analyzer->run();
1640+
1641+
$this->logger->add( 'Finished analyzing filelist!' );
1642+
$this->logger->add_memory();
1643+
}
1644+
16331645
/*
16341646
* Use the chosen compressor to build an archive.
16351647
* If the is no available compressor, then return an error.
@@ -1696,6 +1708,7 @@ public function archive_files( &$info ) {
16961708
}
16971709

16981710
if ( ! empty( $status['error'] ) ) {
1711+
$this->logger->add( $status['error'] );
16991712
return $status;
17001713
}
17011714

admin/class-boldgrid-backup-admin-environment.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* File: class-boldgrid-backup-admin-environment.php
44
*
55
* @link https://www.boldgrid.com
6-
* @since SINCEVERSION
6+
* @since 1.14.5
77
*
88
* @package Boldgrid_Backup
99
* @subpackage Boldgrid_Backup/admin
@@ -18,7 +18,7 @@
1818
* The purpose of this class is to help us get more information about our environment. It should also
1919
* help answer questions, such as, has our environment changed?
2020
*
21-
* @since SINCEVERSION
21+
* @since 1.14.5
2222
*/
2323
class Boldgrid_Backup_Admin_Environment {
2424
/**
@@ -27,15 +27,15 @@ class Boldgrid_Backup_Admin_Environment {
2727
* For example, to know if something has changed in the environment, we'll need to know both the
2828
* old values and the new values. The old values will be stored in this option.
2929
*
30-
* @since SINCEVERSION
30+
* @since 1.14.5
3131
* @var string
3232
*/
3333
const OPTION_NAME = 'boldgrid_backup_environment';
3434

3535
/**
3636
* Determine whether or not our environment has changed.
3737
*
38-
* @since SINCEVERSION
38+
* @since 1.14.5
3939
*
4040
* @return bool
4141
*/
@@ -62,7 +62,7 @@ public function has_changed() {
6262
/**
6363
* Determine whether or not our hostname has changed.
6464
*
65-
* @since SINCEVERSION
65+
* @since 1.14.5
6666
*
6767
* @return bool
6868
*/
@@ -84,7 +84,7 @@ public function has_hostname_changed() {
8484
/**
8585
* Determine whether or not our php version has changed.
8686
*
87-
* @since SINCEVERSION
87+
* @since 1.14.5
8888
*
8989
* @return bool
9090
*/
@@ -106,7 +106,7 @@ public function has_phpversion_changed() {
106106
/**
107107
* Determine whether or not our WordPress version has changed.
108108
*
109-
* @since SINCEVERSION
109+
* @since 1.14.5
110110
*
111111
* @global string $wp_version The current WordPress version.
112112
*
@@ -131,7 +131,7 @@ public function has_wpversion_changed() {
131131
/**
132132
* Get a saved environment value.
133133
*
134-
* @since SINCEVERSION
134+
* @since 1.14.5
135135
*
136136
* @access private
137137
* @see self::OPTION_NAME
@@ -149,7 +149,7 @@ private function get_saved_value( $key, $default = false ) {
149149
/**
150150
* Get all of our saved values.
151151
*
152-
* @since SINCEVERSION
152+
* @since 1.14.5
153153
*
154154
* @access private
155155
* @see self::OPTION_NAME
@@ -163,7 +163,7 @@ private function get_saved_values() {
163163
/**
164164
* Save a specific environment value.
165165
*
166-
* @since SINCEVERSION
166+
* @since 1.14.5
167167
*
168168
* @access private
169169
* @see self::OPTION_NAME
@@ -182,7 +182,7 @@ private function save_value( $key, $value ) {
182182
/**
183183
* Save all of our environment values.
184184
*
185-
* @since SINCEVERSION
185+
* @since 1.14.5
186186
*
187187
* @access private
188188
* @see self::OPTION_NAME
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
<?php
2+
/**
3+
* File: class-boldgrid-backup-admin-filelist-analyzer.php
4+
*
5+
* @link https://www.boldgrid.com
6+
* @since SINCEVERSION
7+
*
8+
* @package Boldgrid_Backup
9+
* @subpackage Boldgrid_Backup/admin
10+
* @copyright BoldGrid
11+
* @version $Id$
12+
* @author BoldGrid <support@boldgrid.com>
13+
*/
14+
15+
/**
16+
* Class: Boldgrid_Backup_Admin_Filelist
17+
*
18+
* @since SINCEVERSION
19+
*/
20+
class Boldgrid_Backup_Admin_Filelist_Analyzer {
21+
/**
22+
* The key used to save this setting in the Total Upkeep settings.
23+
*
24+
* @since SINCEVERSION
25+
* @var string
26+
*/
27+
public static $settings_key = 'filelist_analysis';
28+
29+
/**
30+
* The unix timestamp used for the parent backup's log file.
31+
*
32+
* This is passed in via the constructor, and is only used when creating the log file. We want
33+
* the unixtime in the "backup" and "backup filelist" log fies to match so you know their is a
34+
* relationship.
35+
*
36+
* @since SINCEVERSION
37+
* @access private
38+
* @var int
39+
*/
40+
private $log_time;
41+
42+
/**
43+
* An array of files.
44+
*
45+
* This is passed in via the contructor. This is the same filelist that is passed to each compressor
46+
* so they know which files to backup.
47+
*
48+
* @since SINCEVERSION
49+
* @access private
50+
* @var array
51+
*/
52+
private $filelist;
53+
54+
/**
55+
* Constructor.
56+
*
57+
* @since SINCEVERSION
58+
*
59+
* @param array $filelist
60+
* @param int $log_time
61+
*/
62+
public function __construct( $filelist = array(), $log_time = 0 ) {
63+
$this->filelist = is_array( $filelist ) ? $filelist : array();
64+
$this->log_time = ! empty( $log_time ) ? $log_time : time();
65+
}
66+
67+
/**
68+
* Whether or not the filelist analyer is enabled.
69+
*
70+
* @since SINCEVERSION
71+
*
72+
* @return bool
73+
*/
74+
public static function is_enabled() {
75+
$core = apply_filters( 'boldgrid_backup_get_core', null );
76+
$setting = $core->settings->get_setting( self::$settings_key );
77+
78+
return ! empty( $setting );
79+
}
80+
81+
/**
82+
* Run.
83+
*
84+
* Do all the magic and write the log file.
85+
*
86+
* @since SINCEVERSION
87+
*/
88+
public function run() {
89+
$core = apply_filters( 'boldgrid_backup_get_core', null );
90+
$logger = new Boldgrid_Backup_Admin_Log( $core );
91+
92+
$size_by_extension = array();
93+
$count_by_extension = array();
94+
$size_by_dir = array();
95+
96+
$logger->init( 'archive-' . $this->log_time . '-filelist.log' );
97+
98+
// Loop through each file.
99+
foreach ( $this->filelist as $file ) {
100+
$extension = pathinfo( $file[1], PATHINFO_EXTENSION );
101+
$dir = dirname( $file[1] );
102+
103+
// Generate our stats.
104+
$size_by_extension[ $extension ] = empty( $size_by_extension[ $extension ] ) ? $file[2] : $size_by_extension[ $extension ] + $file[2];
105+
$count_by_extension[ $extension ] = empty( $count_by_extension[ $extension ] ) ? 1 : $count_by_extension[ $extension ] + 1;
106+
$size_by_dir[ $dir ] = empty( $size_by_dir[ $dir ] ) ? $file[2] : $size_by_dir[ $dir ] + $file[2];
107+
}
108+
109+
// Display top 100 files.
110+
$limit = 100;
111+
$to_show = count( $size_by_extension ) >= $limit ? $limit : count( $size_by_extension );
112+
$key = 1;
113+
114+
$logger->add_separator();
115+
$logger->add( 'LARGEST FILES' );
116+
117+
usort( $this->filelist, function ( $item1, $item2 ) {
118+
return $item1[2] <= $item2[2] ? 1 : -1;
119+
} );
120+
121+
foreach ( $this->filelist as $file ) {
122+
$logger->add( '(' . $key . ') ' . $file[1] . ' - ' . size_format( $file[2], 2 ) );
123+
124+
$key++;
125+
if ( $key > $to_show ) {
126+
break;
127+
}
128+
}
129+
130+
// Display size by extension.
131+
$limit = 30;
132+
$to_show = count( $size_by_extension ) >= $limit ? $limit : count( $size_by_extension );
133+
$key = 1;
134+
135+
$logger->add_separator();
136+
$logger->add( 'SIZE BY EXTENSION' );
137+
138+
arsort( $size_by_extension );
139+
140+
foreach ( $size_by_extension as $extension => $size ) {
141+
$logger->add( '(' . $key . ') .' . $extension . ' - ' . number_format( $count_by_extension[ $extension ] ) . ' files totaling ' . size_format( $size, 2 ) );
142+
143+
$key++;
144+
if ( $key > $to_show ) {
145+
break;
146+
}
147+
}
148+
149+
// Display size by directory.
150+
$limit = 30;
151+
$to_show = count( $size_by_dir ) >= $limit ? $limit : count( $size_by_dir );
152+
$key = 1;
153+
154+
$logger->add_separator();
155+
$logger->add( 'SIZE BY DIRECTORY' );
156+
157+
arsort( $size_by_dir );
158+
159+
foreach ( $size_by_dir as $directory => $size ) {
160+
$logger->add( '(' . $key . ') ' . $directory . ' - ' . size_format( $size, 2 ) );
161+
162+
$key++;
163+
if ( $key > $to_show ) {
164+
break;
165+
}
166+
}
167+
}
168+
}

0 commit comments

Comments
 (0)