-
Notifications
You must be signed in to change notification settings - Fork 0
/
breakdance-search-replace.php
46 lines (32 loc) · 1.36 KB
/
breakdance-search-replace.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
function breakdance_search_replace( $from, $to ) {
printf( "Running Breakdance Search-Replace from: %s to: %s...\n\r", $from, $to );
$affectedValues = \Breakdance\Setup\replaceUrls($from, $to);
if (is_wp_error($affectedValues)) {
/** @psalm-suppress PossiblyInvalidMethodCall */
echo $affectedValues->get_error_message();
echo "\r\n";
return;
}
/** @var array{postMeta: string, preferences: boolean} $affectedValues */
$affectedValues = $affectedValues;
/** @psalm-suppress PossiblyInvalidArgument */
echo (sprintf("%s rows affected.\n\r", $affectedValues['postMeta']));
// always regenerate fonts, even if no replace was done
// a user may have used a tool like "Search And Replace" to update all their URLs
// and then run this tool for fonts, or just to verify everything was replaced
/** @psalm-suppress UndefinedFunction
* @var array{error?: string} $fontFilesRegenerated
*/
$fontFilesRegenerated = \Breakdance\CustomFonts\regenerateFontFiles();
if (isset($fontFilesRegenerated['error'])) {
echo "Error regenerating font files: " . $fontFilesRegenerated['error'] . "\n\r";
}
}
if ( empty( $args ) ) {
echo "Usage: wp eval-file breakdance-search-replace.php <from> <to>\n";
exit(1);
}
$from = $args[1];
$to = $args[2];
breakdance_search_replace( $from, $to );