Skip to content

Commit

Permalink
fix: corrected indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lgersman committed Jul 24, 2023
1 parent 83b8937 commit c609c48
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 68 deletions.
42 changes: 21 additions & 21 deletions impex-cli/impex-cli.php
Expand Up @@ -4,8 +4,8 @@
# Description: commandline tool to import/export wordpress data by interacting with the cm4all-wp-impex wordpress plugin
#
# This file is part of cm4all-wp-impex.
#
# Usage: see impex-cli/impex-cli.php help
#
# Usage: see impex-cli/impex-cli.php help
#
# Requires PHP: 8.0, php-curl extension
# Author: Lars Gersmann<lars.gersmann@cm4all.com>
Expand Down Expand Up @@ -205,7 +205,7 @@ function help($options, $message = null, ...$args)

echo "Usage: impex-cli.php [operation] [sub-operation?] -rest-url=[wordpress-restapi-url] [options] [arguments]
operation:
operation:
help show this help
export export wordpress data using the impex wordpress plugin to a directory
Expand All @@ -214,32 +214,32 @@ function help($options, $message = null, ...$args)
arguments:
[directory] (required) directory to export to
import import wordpress data (in impex format) from a directory
import import wordpress data (in impex format) from a directory
options:
-profile=[import-profile] (default='all') import profile to use
-options=[import options in JSON format] (default='{}') provide options to the import process
arguments:
[directory] (required) impex directory to import from
export-profile
export-profile
sub-operations: (required)
list json list of known impex export profiles
list json list of known impex export profiles
import-profile
import-profile
sub-operations: (required)
list json list of known impex import profiles
list json list of known impex import profiles
global options:
-username=[wordpress-username]
-password=[wordpress-password]
-username=[wordpress-username]
-password=[wordpress-password]
-rest-url=[wordpress-restapi-url] (required) url of wordpress rest endpoint
example: -rest-url=http://localhost:8888/wp-json
-verbose prints additional informations to stderr
-CURLOPT_VERBOSE prints additional php-curl debug informations stderr
-H=[header] additional header to send to the wordpress rest api
may occur multiple times
example: -H='x-foo: bar'
example: -H='x-foo: bar'
see https://ionos-wordpress.github.io/cm4all-wp-impex/impex-cli.html for more.
";
Expand Down Expand Up @@ -354,8 +354,8 @@ function import($options, $import_directory, ...$args)
$import_options = $options['options'] ?? '{}';
try {
$import_options = json_decode(
json: $import_options,
associative: true,
json: $import_options,
associative: true,
flags: JSON_THROW_ON_ERROR,
);
} catch(Exception $ex) {
Expand Down Expand Up @@ -467,14 +467,14 @@ function ($curl) use ($slice, $slice_contents, $chunk_dir, $slice_file, $options
"import/$import_id/consume",
\CURLOPT_POST,
);

$postConsumeCallbacks = $result['callbacks'] ?? [];
foreach($postConsumeCallbacks as $index => $postConsumeCallback) {
_log(
$options,
'Executing post consume callback(path=%s, method=%s) with data(=%s)',
$postConsumeCallback['path'],
$postConsumeCallback['method'],
$options,
'Executing post consume callback(path=%s, method=%s) with data(=%s)',
$postConsumeCallback['path'],
$postConsumeCallback['method'],
json_encode($postConsumeCallback['data']),
);
[$result, $status, $error] = _curl(
Expand All @@ -483,7 +483,7 @@ function ($curl) use ($slice, $slice_contents, $chunk_dir, $slice_file, $options
$postConsumeCallback['method']==='post' ? \CURLOPT_POST : null,
fn ($curl) => curl_setopt($curl, \CURLOPT_POSTFIELDS, http_build_query($postConsumeCallback['data']))
);

if ($error) {
_log($options, "Warning : Failed to update metadata : HTTP status(=%s) : %s", $status, $error);
}
Expand Down Expand Up @@ -664,7 +664,7 @@ function _saveSlicesChunk($options, $export_directory, $response, $chunk)
// if we are running in cli mode and not as phpunit test then run main
if (php_sapi_name() === "cli" && !str_ends_with($_SERVER['argv'][0], 'phpunit')) {
main($argv);
}
}

/*
main([
Expand All @@ -677,4 +677,4 @@ function _saveSlicesChunk($options, $export_directory, $response, $chunk)
"-profile=all",
"~/Sync/tmp/snapshots/my-export",
]);
*/
*/
8 changes: 4 additions & 4 deletions plugins/cm4all-wp-impex/profiles/export-profile-base.php
Expand Up @@ -22,16 +22,16 @@

// export most common used wp options
$profile->addTask(
'common wp_options',
WpOptionsExporter::PROVIDER_NAME,
'common wp_options',
WpOptionsExporter::PROVIDER_NAME,
[WpOptionsExporter::OPTION_SELECTOR => [
'page_on_front', // wordpress homepage
'show_on_front', // what should be shown ('page'| 'post' ...)
'page_for_posts', // posts homepage

'blogname', // aka website title
'blogdescription',
'blogdescription',
'site_logo', // website logo
'site_icon' // website icon
],],
);
);
10 changes: 5 additions & 5 deletions plugins/cm4all-wp-impex/tests/phpunit/impex-unittestcase.php
Expand Up @@ -22,16 +22,16 @@ public function setUp()
self::_resetImpex();
}

/**
/**
* Triggers the ImpEx actions for provider and profile registration so that all by default loaded prviders and profiles will be available.
*
*
* Regularly the Implex plugin will trigger the actions
* - Impex::WP_ACTION_REGISTER_PROVIDERS
* - Impex::WP_ACTION_REGISTER_PROFILES
* automatically.
*
* automatically.
*
* But ImpexUnitTestcase->setUp resets all registered providers/profiles for convenience.
*
*
* So we need to trigger the registration actions again in rare cases
*/
protected function __invokeImpexActions(): void
Expand Down
Expand Up @@ -34,7 +34,7 @@ function testDbExporter(): void
// system('mysql --user=' . DB_USER . ' --password=' . DB_PASSWORD . ' ' . DB_NAME . ' < ' . __DIR__ . '/fixtures/adapter/db/cmplz-plugin.sql');

/*
this is a bit quirky ... wp unit tests apply a query filter to wpdb which transforms CREATE/DROP table statements
this is a bit quirky ... wp unit tests apply a query filter to wpdb which transforms CREATE/DROP table statements
into CREATE/DROP TEMPORARY table statements (https://wordpress.stackexchange.com/questions/220275/wordpress-unit-testing-cannot-create-tables)
therefore tables created in wp unit tests are not visible using SHOW TABLES LIKE statements.
Expand Down
Expand Up @@ -121,7 +121,7 @@ public function test_get_item()
$request->set_body(\wp_json_encode(['profile' => $profile->name]));
$create_response = $this->server->dispatch($request);

// try to get it
// try to get it
$request = new \WP_REST_Request('GET', ImpexRestController::BASE_URI . ImpexExportRESTController::REST_BASE . '/' . $create_response->data['id']);
$response = $this->server->dispatch($request);
$this->assertEquals(200, $response->status);
Expand Down Expand Up @@ -222,7 +222,7 @@ public function test_get_item_slices()
{
\wp_set_current_user($this->user);

// create export
// create export
$alphabet = range('a', 'z');
$profile = $this->__createExportProfile('single-slice-export-profile', ['provider-alphabet' => $alphabet]);

Expand All @@ -244,7 +244,7 @@ public function test_get_item_slices()
$response = $this->server->dispatch($request);
$this->assertEquals(404, $response->status);

// get export slices using rest pagination api
// get export slices using rest pagination api
$request = new \WP_REST_Request('GET', ImpexRestController::BASE_URI . ImpexExportRESTController::REST_BASE . '/' . $export_id . '/slice');
$request->set_query_params(['offset' => 1, 'per_page' => 2, 'page' => 2]);
$response = $this->server->dispatch($request);
Expand Down
8 changes: 4 additions & 4 deletions plugins/cm4all-wp-impex/tests/phpunit/test-impex-export.php
Expand Up @@ -18,9 +18,9 @@ function setUp()
parent::setUp();

/*
CAVEAT : tables created using WordPress install/upgrade mechanism
(https://codex.wordpress.org/Creating_Tables_with_Plugins) will not use
the wp phpunit filter making the table temporary.
CAVEAT : tables created using WordPress install/upgrade mechanism
(https://codex.wordpress.org/Creating_Tables_with_Plugins) will not use
the wp phpunit filter making the table temporary.
=> so we need to drop the table manually to have a consistent setup
*/
Expand Down Expand Up @@ -92,7 +92,7 @@ function testExportDbTablesInstalled(): void
global $wpdb;

/*
this is a bit quirky ... wp unit tests apply a query filter to wpdb which transforms CREATE/DROP table statements
this is a bit quirky ... wp unit tests apply a query filter to wpdb which transforms CREATE/DROP table statements
into CREATE/DROP TEMPORARY table statements (https://wordpress.stackexchange.com/questions/220275/wordpress-unit-testing-cannot-create-tables)
therefore tables created in wp unit tests are not visible using SHOW TABLES LIKE statements.
Expand Down
Expand Up @@ -166,7 +166,7 @@ function ($uploads) {



// create initial attachment
// create initial attachment
$post = $this->factory->post->create_and_get();
$attachment_id = $this->factory->attachment->create_upload_object(__DIR__ . '/fixtures/uploads/images/' . self::IMAGE, $post->ID);

Expand Down
Expand Up @@ -187,7 +187,7 @@ function testContentImporterUsers()
$this->assertIsObject($t);
}

// test import with valid user options
// test import with valid user options
$new_id_exported_user2 = self::factory()->user->create(['role' => 'editor', 'user_login' => 'new_id_exported_user2']);
$users_before_import = \get_users();
$this->assertCount(6, $users_before_import);
Expand All @@ -207,7 +207,7 @@ function testContentImporterUsers()
$this->assertEmpty(array_filter($users_before_import, fn ($user) => $user->data->user_login === 'non_existing_user'));
$this->assertCount(1, array_filter($users_after_import, fn ($user) => $user->data->user_login === 'non_existing_user'));

// test imported post is attached to user
// test imported post is attached to user
// $post = \get_page_by_title('post from exported_user', \OBJECT, 'post');
// \get_page_by_title iss deprecated since wp 6.2
$posts = \get_posts([
Expand Down Expand Up @@ -278,7 +278,7 @@ function testContentImporterUsers()

function testContentImporterCategories()
{
/*
/*
setup test data
*/
$slices = (function (): array {
Expand Down Expand Up @@ -323,7 +323,7 @@ function testContentImporterCategories()
$this->assertTrue(in_array('simple', array_column($categories, 'name')), 'only category "simple" should exist');
$this->assertEmpty(\get_posts(), 'no posts should exist');

// execute import
// execute import
$retVal = call_user_func($provider->callback, $slices[0], [], $importContext,);
$this->assertTrue($retVal, 'importer callback expected to return successful');

Expand Down Expand Up @@ -405,7 +405,7 @@ function testContentImporterTerms()
$this->assertCount(4, $terms, 'only terms "food", "fruits", "apples" and "pears" should exist');
$this->assertEmpty(\get_posts(), 'no posts should exist');

// execute import
// execute import
$retVal = call_user_func($provider->callback, $slices[0], [], $importContext,);
$this->assertTrue($retVal, 'importer callback expected to return successful');

Expand All @@ -428,7 +428,7 @@ function testContentImporterTerms()
$success = \unregister_taxonomy('products');
$this->assertTrue($success, 'taxonomy "products" should be unregistered');

// execute import
// execute import
$retVal = call_user_func($provider->callback, $slices[0], [], $importContext,);
$this->assertTrue($retVal, 'importer callback expected to return successful');

Expand Down Expand Up @@ -523,7 +523,7 @@ function testContentImporterTags()
$tags = \get_tags(['hide_empty' => false,]);
$this->assertCount(2, $tags, 'only terms "alpha", and "beta" should exist');

// execute import
// execute import
$retVal = call_user_func($provider->callback, $slices[0], [], $importContext,);
$this->assertTrue($retVal, 'importer callback expected to return successful');

Expand Down Expand Up @@ -551,7 +551,7 @@ function testContentImporterNavMenu(): void
$user = self::factory()->user->create(['user_login' => 'editor']);
\wp_set_current_user($user);

// create a nav menu
// create a nav menu
$navmenu_id = \wp_create_nav_menu('my navmenu');

// create some posts and attach them to the nav menu
Expand Down Expand Up @@ -609,7 +609,7 @@ function testContentImporterNavMenu(): void
$provider = __registerContentImportProvider();
$importContext = $this->_createImpexImportTransformationContextMock();

// execute import
// execute import
$retVal = call_user_func($provider->callback, $slices[0], [], $importContext,);
$this->assertTrue($retVal, 'importer callback expected to return successful');

Expand Down
Expand Up @@ -97,7 +97,7 @@ function testImport_OPTION_COPY_DATA_FROM_TABLE_WITH_PREFIX(): void
{
global $wpdb;

// drop (previously created by this function) table if exists
// drop (previously created by this function) table if exists
$wpdb->query("DROP TABLE IF EXISTS live_cmplz_cookies");

// register importer/exporter
Expand Down Expand Up @@ -143,7 +143,7 @@ function testImport_OPTION_COPY_DATA_FROM_TABLE_WITH_PREFIX(): void
$source_table = "{$wpdb->prefix}cmplz_cookies";

/*
this is a bit quirky ... wp unit tests apply a query filter to wpdb which transforms CREATE/DROP table statements
this is a bit quirky ... wp unit tests apply a query filter to wpdb which transforms CREATE/DROP table statements
into CREATE/DROP TEMPORARY table statements (https://wordpress.stackexchange.com/questions/220275/wordpress-unit-testing-cannot-create-tables)
therefore tables created in wp unit tests are not visible using SHOW TABLES LIKE statements.
Expand Down
Expand Up @@ -113,7 +113,7 @@ public function test_get_item()
// create import
$import_id = Impex::getInstance()->Import->create(Impex::getInstance()->Import->addProfile('dummy-import'))->id;

// try to get it
// try to get it
$request = new \WP_REST_Request('GET', ImpexRestController::BASE_URI . ImpexImportRESTController::REST_BASE . '/' . $import_id);
$response = $this->server->dispatch($request);
$this->assertEquals(200, $response->status);
Expand Down Expand Up @@ -218,8 +218,8 @@ public function test_delete_item()
}

/*
testcase is obsolete since it utilizes the removed WordPress Importer
@TODO : adapt testcase to new ContentImporter
testcase is obsolete since it utilizes the removed WordPress Importer
@TODO : adapt testcase to new ContentImporter
*/
public function _test_upsert_item_slices()
{
Expand Down Expand Up @@ -255,7 +255,7 @@ function ($_) use ($EXPORT_PATH) {
if ($slice_json[Impex::SLICE_TAG] === 'attachment') {
$attachment_filename = $EXPORT_PATH . '/' . basename($slice_file, '.json') . '-' . basename($slice_json[Impex::SLICE_DATA]);

// ATTENTION: we need to make a copy of the file since attachment importer will move the uploaded file
// ATTENTION: we need to make a copy of the file since attachment importer will move the uploaded file
$uploadedAttachment = tempnam(sys_get_temp_dir(), 'impex_import_');
$success = file_put_contents($uploadedAttachment, file_get_contents($attachment_filename));

Expand All @@ -281,7 +281,7 @@ function ($_) use ($EXPORT_PATH) {
));
$this->assertEquals(count($slice_filenames), $inserted_slices, 'all uploaded chunks should be in the database');

// try to insert the slices again
// try to insert the slices again
foreach ($slice_filenames as $index => $slice_filename) {
$slice_file = $EXPORT_PATH . '/' . $slice_filename;

Expand All @@ -296,7 +296,7 @@ function ($_) use ($EXPORT_PATH) {
if ($slice_json[Impex::SLICE_TAG] === 'attachment') {
$attachment_filename = $EXPORT_PATH . '/' . basename($slice_file, '.json') . '-' . basename($slice_json[Impex::SLICE_DATA]);

// ATTENTION: we need to make a copy of the file since attachment importer will move the uploaded file
// ATTENTION: we need to make a copy of the file since attachment importer will move the uploaded file
$uploadedAttachment = tempnam(sys_get_temp_dir(), 'impex_import_');
$success = file_put_contents($uploadedAttachment, file_get_contents($attachment_filename));

Expand Down

0 comments on commit c609c48

Please sign in to comment.