Skip to content

Commit 3cdb5f2

Browse files
authored
Merge pull request #87 from WP2Static/infinite-crawl
infinite crawl, flat files to DB
2 parents e71b926 + 14945c0 commit 3cdb5f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1663
-1884
lines changed

composer.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
Contributors: leonstafford
33
Tags: security, performance, static
44
Requires at least: 3.2
5-
Tested up to: 5.4.1
5+
Tested up to: 5.4.2
66
Requires PHP: 7.3
7-
Stable tag: 6.6.18
7+
Stable tag: 6.6.19
88

99
Publish your website as static HTML for improved performance and security.
1010

@@ -128,8 +128,10 @@ Everyone's WordPress hosting environment and configuration is unique, with diffe
128128

129129
== Changelog ==
130130

131-
= 6.6.18 =
131+
= 6.6.19 =
132132

133+
* granular crawl and deploy progress indicators
134+
* no more txt files polluting uploads dir, slowing things down
133135
* progress indicator on WP_CLI generate cmd
134136
* finally supporting UTF/multibyte URLs!
135137
* preserve font hex values in parsed stylesheets

src/Archive.php

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,63 +17,13 @@ public function __construct() {
1717
[ 'wpenv' ]
1818
);
1919

20-
$this->path = '';
21-
$this->name = '';
22-
}
23-
24-
public function setToCurrentArchive() : void {
25-
$handle = fopen(
26-
$this->settings['wp_uploads_path'] .
27-
'/WP2STATIC-CURRENT-ARCHIVE.txt',
28-
'r'
29-
);
30-
31-
if ( ! is_resource( $handle ) ) {
32-
return;
33-
}
34-
35-
$path = stream_get_line( $handle, 0 );
36-
37-
if ( ! $path ) {
38-
return;
39-
}
40-
41-
$this->path = $path;
20+
$this->path = $this->settings['wp_uploads_path'] . '/static-html-output/';
4221
$this->name = basename( $this->path );
4322
}
4423

45-
public function currentArchiveExists() : bool {
46-
return is_file(
47-
$this->settings['wp_uploads_path'] .
48-
'/WP2STATIC-CURRENT-ARCHIVE.txt'
49-
);
50-
}
51-
5224
public function create() : void {
53-
$this->name = $this->settings['wp_uploads_path'] .
54-
'/wp-static-html-output-' . time();
55-
56-
$this->path = $this->name . '/';
57-
$this->name = basename( $this->path );
58-
59-
if ( wp_mkdir_p( $this->path ) ) {
60-
$result = file_put_contents(
61-
$this->settings['wp_uploads_path'] .
62-
'/WP2STATIC-CURRENT-ARCHIVE.txt',
63-
$this->path
64-
);
65-
66-
if ( ! $result ) {
67-
WsLog::l( 'USER WORKING DIRECTORY NOT WRITABLE' );
68-
}
69-
70-
chmod(
71-
$this->settings['wp_uploads_path'] .
72-
'/WP2STATIC-CURRENT-ARCHIVE.txt',
73-
0664
74-
);
75-
} else {
76-
WsLog::l( "Couldn't create archive directory at $this->path" );
25+
if ( ! wp_mkdir_p( $this->path ) ) {
26+
Logger::l( "Couldn't create archive directory at $this->path" );
7727
}
7828
}
7929
}

src/ArchiveProcessor.php

Lines changed: 4 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,9 @@ class ArchiveProcessor extends StaticHTMLOutput {
1212
* @var Archive
1313
*/
1414
public $archive;
15-
/**
16-
* @var string
17-
*/
18-
public $target_folder;
1915

2016
public function __construct() {
2117
$this->archive = new Archive();
22-
$this->archive->setToCurrentArchive();
2318

2419
$this->loadSettings(
2520
[
@@ -29,14 +24,13 @@ public function __construct() {
2924
'processing',
3025
'netlify',
3126
'zip',
32-
'folder',
3327
]
3428
);
3529
}
3630

3731
public function renameWPDirectory( string $source, string $target ) : void {
3832
if ( empty( $source ) || empty( $target ) ) {
39-
WsLog::l(
33+
Logger::l(
4034
'Failed trying to rename: ' .
4135
'Source: ' . $source .
4236
' to: ' . $target
@@ -54,7 +48,7 @@ public function renameWPDirectory( string $source, string $target ) : void {
5448
$original_dir
5549
);
5650
} else {
57-
WsLog::l(
51+
Logger::l(
5852
'Trying to rename non-existent directory: ' .
5953
$original_dir
6054
);
@@ -146,89 +140,6 @@ public function put_safety_file( string $dirname ) : bool {
146140
return true;
147141
}
148142

149-
public function copyStaticSiteToPublicFolder() : void {
150-
if ( $this->settings['selected_deployment_option'] === 'folder' ) {
151-
$target_folder = trim( $this->settings['targetFolder'] );
152-
$this->target_folder = $target_folder;
153-
154-
if ( ! $target_folder ) {
155-
return;
156-
}
157-
158-
// instantiate with safe defaults
159-
$directory_exists = true;
160-
$directory_empty = false;
161-
$dir_has_safety_file = false;
162-
163-
// CHECK #1: directory exists or can be created
164-
$directory_exists = is_dir( $target_folder );
165-
166-
if ( $directory_exists ) {
167-
$directory_empty = $this->dir_is_empty( $target_folder );
168-
} else {
169-
if ( wp_mkdir_p( $target_folder ) ) {
170-
if ( ! $this->put_safety_file( $target_folder ) ) {
171-
WsLog::l(
172-
'Couldn\'t put safety file in ' .
173-
'Target Directory' .
174-
$target_folder
175-
);
176-
177-
die();
178-
}
179-
} else {
180-
WsLog::l(
181-
'Couldn\'t create Target Directory: ' .
182-
$target_folder
183-
);
184-
185-
die();
186-
}
187-
}
188-
189-
// CHECK #2: check directory empty and add safety file
190-
if ( $directory_empty ) {
191-
if ( ! $this->put_safety_file( $target_folder ) ) {
192-
WsLog::l(
193-
'Couldn\'t put safety file in ' .
194-
'Target Directory' .
195-
$target_folder
196-
);
197-
198-
die();
199-
}
200-
}
201-
202-
$dir_has_safety_file =
203-
$this->dir_has_safety_file( $target_folder );
204-
205-
if ( $directory_empty || $dir_has_safety_file ) {
206-
$this->recursive_copy(
207-
$this->archive->path,
208-
$this->target_folder
209-
);
210-
211-
if ( ! $this->put_safety_file( $target_folder ) ) {
212-
WsLog::l(
213-
'Couldn\'t put safety file in ' .
214-
'Target Directory' .
215-
$target_folder
216-
);
217-
218-
die();
219-
}
220-
} else {
221-
WsLog::l(
222-
'Target Directory wasn\'t empty ' .
223-
'or didn\'t contain safety file ' .
224-
$target_folder
225-
);
226-
227-
die();
228-
}
229-
}
230-
}
231-
232143
public function createNetlifySpecialFiles() : void {
233144
if ( $this->settings['selected_deployment_option'] !== 'netlify' ) {
234145
return;
@@ -262,7 +173,7 @@ public function create_zip() : void {
262173
$zip_archive = new ZipArchive();
263174

264175
if ( $zip_archive->open( $temp_zip, ZIPARCHIVE::CREATE ) !== true ) {
265-
WsLog::l( 'Could not create archive' );
176+
Logger::l( 'Could not create archive' );
266177
return;
267178
}
268179

@@ -284,7 +195,7 @@ public function create_zip() : void {
284195
str_replace( $this->archive->path, '', $filename )
285196
)
286197
) {
287-
WsLog::l( 'Could not add file: ' . $filename );
198+
Logger::l( 'Could not add file: ' . $filename );
288199
return;
289200
}
290201
}

0 commit comments

Comments
 (0)