-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
399 additions
and
350 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
use Rowbot\URL\URL; | ||
|
||
require_once __DIR__ . "/../bootstrap.php"; | ||
|
||
if ( $argc < 2 ) { | ||
echo "Usage: php script.php <command> --file <input-file> --from-site-url <current site url> --to-url <target url>\n"; | ||
echo "Commands:\n"; | ||
echo " list_urls: List all the URLs found in the input file.\n"; | ||
echo " migrate_urls: Migrate all the URLs found in the input file from the current site to the target site.\n"; | ||
exit( 1 ); | ||
} | ||
|
||
$command = $argv[1]; | ||
$options = []; | ||
|
||
for ( $i = 2; $i < $argc; $i ++ ) { | ||
if ( str_starts_with( $argv[ $i ], '--' ) && isset( $argv[ $i + 1 ] ) ) { | ||
$options[ substr( $argv[ $i ], 2 ) ] = $argv[ $i + 1 ]; | ||
$i ++; | ||
} | ||
} | ||
|
||
if ( ! isset( $options['file'] ) ) { | ||
echo "The file option is required.\n"; | ||
exit( 1 ); | ||
} | ||
|
||
$inputFile = $options['file']; | ||
$targetDomain = @$options['target-domain']; | ||
|
||
if ( ! file_exists( $inputFile ) ) { | ||
echo "The file $inputFile does not exist.\n"; | ||
exit( 1 ); | ||
} | ||
|
||
$block_markup = file_get_contents( $inputFile ); | ||
|
||
// @TODO: Should a base URL be always required? | ||
$previous_url = $options['from-site-url'] ?? 'https://w.org'; | ||
$p = new WP_Block_Markup_Url_Processor( $block_markup, $previous_url ); | ||
|
||
switch ( $command ) { | ||
case 'list_urls': | ||
echo "URLs found in the markup:\n\n"; | ||
while ( $p->next_url() ) { | ||
// Skip empty relative URLs. | ||
if ( ! trim( $p->get_url() ) ) { | ||
continue; | ||
} | ||
echo '* '; | ||
switch ( $p->get_token_type() ) { | ||
case '#tag': | ||
echo 'In <' . $p->get_tag() . '> tag attribute "' . $p->get_inspected_attribute_name() . '": '; | ||
break; | ||
case '#block-comment': | ||
echo 'In a ' . $p->get_block_name() . ' block attribute "' . $p->get_block_attribute_key() . '": '; | ||
break; | ||
case '#text': | ||
echo 'In #text: '; | ||
break; | ||
} | ||
echo $p->get_url() . "\n"; | ||
} | ||
echo "\n"; | ||
break; | ||
case 'migrate_urls': | ||
if ( ! isset( $options['from-site-url'] ) ) { | ||
echo "The --from-site-url option is required for the migrate_urls command.\n"; | ||
exit( 1 ); | ||
} | ||
if ( ! isset( $options['to-url'] ) ) { | ||
echo "The --to-url option is required for the migrate_urls command.\n"; | ||
exit( 1 ); | ||
} | ||
$parsed_prev_url = URL::parse( $options['from-site-url'] ); | ||
$next_url = $options['to-url']; | ||
$parsed_new_url = URL::parse( $next_url ); | ||
echo "Replacing $previous_url with $next_url in the input.\n"; | ||
echo "Note this is not yet enough to migrate the site as both the previous and the new"; | ||
echo "site might be hosted on specific paths.\n\n"; | ||
while ( $p->next_url() ) { | ||
$updated = false; | ||
$url = $p->get_url(); | ||
$parsed_url = URL::parse( $url, $parsed_prev_url ); | ||
if ( $parsed_url->hostname === $parsed_prev_url->hostname ) { | ||
$parsed_url->hostname = $parsed_new_url->hostname; | ||
if ( str_starts_with( $parsed_url->pathname, $parsed_prev_url->pathname ) ) { | ||
$parsed_url->pathname = $parsed_new_url->pathname . substr( $parsed_url->pathname, strlen( $parsed_prev_url->pathname ) ); | ||
} | ||
$p->set_url( $parsed_url->toString() ); | ||
} | ||
} | ||
echo $p->get_updated_html(); | ||
break; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!-- wp:image {"src": "https://mysite.com/wp-content/image.png", "meta": {"src": "https://mysite.com/wp-content/image.png"}} --> | ||
<img src="https://mysite.com/wp-content/image.png"> | ||
<!-- /wp:image --> | ||
|
||
<!-- wp:paragraph --> | ||
<p>During the <a href="writeofpassage.school">Write of Passage</a>, I stubbornly tried to beat my writer’s block by writing until 3am multiple times. The burnout returned. I dropped everything and went to Greece for a week.</p> | ||
<!-- /wp:paragraph --> | ||
|
||
<!-- wp:paragraph --> | ||
<p> | ||
Have you seen my blog, adamadam.blog? I told a story there of how I got my Bachelor's degree, | ||
check it out: https://adamadam.blog/2021/09/16/how-i-got-bachelors-in-six-months/ | ||
</p> | ||
<!-- /wp:paragraph --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
<phpunit bootstrap="bootstrap.php"> | ||
<phpunit | ||
bootstrap="bootstrap.php" | ||
colors="true" | ||
verbose="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Project Test Suite"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> | ||
</phpunit> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
#!/bin/bash | ||
#COMMAND="phpunit tests/WP_Migration_*" | ||
#COMMAND="phpunit tests/WP_Block_Markup_P*" | ||
COMMAND="phpunit tests/WP_Block_Markup_Url*" | ||
$COMMAND | ||
fswatch -o ./**/*.php | xargs -n1 -I{} $COMMAND | ||
#COMMAND="phpunit tests/*.php" | ||
#COMMAND="phpunit tests/WP_Block_Markup_Url_Processor_Tests.php" | ||
#COMMAND="phpunit -c phpunit.xml" | ||
#$COMMAND | ||
#fswatch -o ./**/*.php | xargs -n1 -I{} $COMMAND | ||
|
||
for i in $(ls tests/*.php | grep -v URL_Parser); do | ||
phpunit $i | ||
done |
Oops, something went wrong.