Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions .env.testing
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
WP_ROOT_FOLDER="../../../"

TEST_SITE_WP_ADMIN_PATH="/wp-admin"
TEST_SITE_DB_NAME="test"
TEST_SITE_DB_HOST="localhost"
TEST_SITE_DB_USER="root"
TEST_SITE_DB_PASSWORD="root"
TEST_SITE_TABLE_PREFIX="wp_"
WP_ADMIN_PATH="/wp-admin"

DB_NAME="test"
DB_HOST="localhost"
DB_USER="root"
DB_PASSWORD="root"
TABLE_PREFIX="wp_"

TEST_SITE_WP_URL="http://localhost:8888"
WP_URL="http://localhost:8888"
DOMAIN="localhost:8888"
ADMIN_EMAIL="admin@localhost.test"
TEST_SITE_ADMIN_USERNAME="root"
TEST_SITE_ADMIN_PASSWORD="root"
ADMIN_USERNAME="root"
ADMIN_PASSWORD="root"
20 changes: 10 additions & 10 deletions _init-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@
);

// Migration page
//$settings->addPage(
// [
// Page::PARENT => 'italystrap-dashboard',
// Page::PAGE_TITLE => __('Migrations', 'italystrap'),
// Page::MENU_TITLE => __('Migrations', 'italystrap'),
// Page::SLUG => 'italystrap-migrations',
// Page::VIEW => ITALYSTRAP_PLUGIN_PATH . '/admin/view/italystrap-migrations.php',
// 'show_on' => \strpos(get_option('template'), 'ItalyStrap') !== false,
// ]
//);
$settings->addPage(
[
Page::PARENT => 'italystrap-dashboard',
Page::PAGE_TITLE => __('Migrations', 'italystrap'),
Page::MENU_TITLE => __('Migrations', 'italystrap'),
Page::SLUG => 'italystrap-migrations',
Page::VIEW => ITALYSTRAP_PLUGIN_PATH . '/admin/view/italystrap-migrations.php',
'show_on' => \strpos((string)get_option('template'), 'ItalyStrap') !== false,
]
);

$settings->addCustomPluginLink(
'key-for-css',
Expand Down
64 changes: 47 additions & 17 deletions admin/view/italystrap-migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,54 @@
<?php // do_action( 'italystrap_before_settings_form', $this ); ?>
<form action="#" method="post">
<?php
// \d($this);

$file = ABSPATH . '.maintenance';
$maintenance_string = '<?php $upgrading = ' . time() . '; ?>';

// $file = new \SplFileObject($file, 'w');
// var_dump($file->fwrite($maintenance_string));
// var_dump($file->fwrite('ciao'));
// var_dump($file);

// delete file
// \unlink($file);

// try {
// \Webimpress\SafeWriter\FileWriter::writeFile($file, $maintenance_string);
// } catch (\Webimpress\SafeWriter\Exception\ExceptionInterface $e) {
// }

// \add_filter(
// 'enable_maintenance_mode',
// function ($bool, $upgrading) {
// \d($bool, $upgrading);
// return false;
// }
// );

$injector = \apply_filters('italystrap_injector', null) ?? new \Auryn\Injector();
try {
$migrations = $injector->make(\ItalyStrap\Migrations\MigrationOld::class);
$migrations->run();

$config = clone $injector->make(\ItalyStrap\Config\ConfigInterface::class);
\d($config);

$option = $injector
->make(\ItalyStrap\Storage\Option::class);
\d($option);
} catch (\Auryn\InjectionException $e) {
echo $e->getMessage();
}

\settings_fields('italystrap-migrations');
// Verify nonce on post action
if (isset($_POST['submit']) && \wp_verify_nonce($_POST['submit'], 'italystrap-migrations')) {
// do stuff
\dd('ciao');
}

// $injector = new \Auryn\Injector();
// $migrations = $injector->make('\\' . \ItalyStrap\Migrations\ParentThemeMigrations::class);

// $migrations = new \ItalyStrap\Migrations\ParentThemeMigrations();
// $migrations->run();
// $this->create_nav_tab();
/**
* Output nonce, action, and option_page fields for a settings page.
*/
// settings_fields( $this->args[ 'options_group' ] );
/**
* Output settings sections and fields
*/
// $this->do_settings_sections( $this->args[ 'options_group' ] );
/**
* Output a submit button
*/
submit_button('Migrate');
?>
</form>
Expand Down
27 changes: 21 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@
"minimum-stability": "stable",
"require": {
"php": ">=7.4",
"italystrap/breadcrumbs": "^2.0",
"italystrap/config": "^2.6",
"italystrap/empress": "^1.0",
"italystrap/event": "dev-master",
"italystrap/edd": "^0.0",
"italystrap/breadcrumbs": "^2.0",
"italystrap/settings": "dev-master",
"italystrap/fields": "^2.0",
"italystrap/helpers": "^1.0",
"italystrap/platform-requirements-check": "dev-master",
"italystrap/settings": "dev-master",
"italystrap/storage": "^1.0",

"mobiledetect/mobiledetectlib": "^2.8",
"cmb2/cmb2": "2.6.0",
"rdlowrey/auryn": "^1.4",
"erusev/parsedown": "^1.6",
"inpsyde/menu-cache": "^1.0"
"inpsyde/menu-cache": "^1.0",
"webimpress/safe-writer": "~2.1.0"
},
"require-dev": {
"lucatume/wp-browser": "^3.1",
Expand All @@ -49,7 +53,7 @@
"vimeo/psalm": "^5.7",
"phpbench/phpbench": "@dev",
"phpmetrics/phpmetrics": "^2.5",
"italystrap/debug": "^2.1",
"italystrap/debug": "dev-master",
"leafo/scssphp": "^0.6",
"rector/rector": "^0.17.7",
"franzl/studio": "^0.16.0"
Expand All @@ -67,7 +71,8 @@
"psr-4": {
"ItalyStrap\\Tests\\": "tests/src",
"ItalyStrap\\Tests\\Unit\\": "tests/unit",
"ItalyStrap\\Tests\\Integration\\": "tests/integration"
"ItalyStrap\\Tests\\Integration\\": "tests/integration",
"ItalyStrap\\Tests\\Functional\\": "tests/functional"
}
},
"extra": {
Expand All @@ -91,6 +96,9 @@
"integration": [
"@php vendor/bin/codecept run integration"
],
"functional": [
"@php vendor/bin/codecept run functional"
],
"infection": [
"@php vendor/bin/infection --threads=4"
],
Expand All @@ -105,6 +113,12 @@
],
"insights": [
"vendor/bin/phpinsights"
],
"qa": [
"@cs",
"@unit",
"@integration",
"@functional"
]
},
"support" : {
Expand All @@ -115,7 +129,8 @@
"allow-plugins": {
"codeception/c3": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"franzl/studio": true
"franzl/studio": true,
"ocramius/package-versions": true
}
}
}
33 changes: 33 additions & 0 deletions src/Migrations/ImageUrlToIdProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace ItalyStrap\Migrations;

class ImageUrlToIdProcessor implements ProcessorInterface
{

public function process($value)
{
if (!\is_string($value)) {
return $value;
}

if (!\preg_match('#png|jpg|gif#is', $value)) {
return $value;
}

return $this->getImageIdFromUrl((string)$value);
}

private function getImageIdFromUrl(string $image_url): int
{
$attachment_id = \attachment_url_to_postid($image_url);
//
// if (0 === $attachment_id) {
// $attachment_id = $this->uploadImageFromUrl($image_url);
// }
//
// return $attachment_id;

return \ItalyStrap\Core\get_image_id_from_url($image_url);
}
}
40 changes: 40 additions & 0 deletions src/Migrations/MigrationHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace ItalyStrap\Migrations;

class MigrationHandler
{
private $steps = [];
private $errors = [];

public function addStep(StepInterface $step): void
{
$this->steps[] = $step;
}

public function run(): bool
{
foreach ($this->steps as $step) {
if (!$step->execute()) {
$this->errors[] = $step->getMessage();
$this->rollback();
return false;
}
}
return true;
}

private function rollback(): void
{
foreach ($this->steps as $step) {
$step->rollback();
}
}

public function getErrors(): array
{
return $this->errors;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ItalyStrap\Migrations;

class ParentThemeMigrations
class MigrationOld
{
private ?RenameDirectory $rename = null;
private ?Update_File $update = null;
Expand All @@ -18,28 +18,41 @@ public function __construct(RenameDirectory $rename, Update_File $update)
public function run()
{

printf(
\printf(
'<h2>%s</h2><p>%s</p><p>Option template name: %s</p><p>Option stylesheet name: %s</p>',
__('Migration page for ItalyStrap theme framework', 'italystrap'),
__('Before upgrading to new version of the ItalyStrap theme framework (4.x) you need to migrate the old settings and rename the old directory of the theme to the new format "italystrap", update the style.css in your child theme to point to the correct parent directory and update the option "template" to the new format name.<br>To do so you can use the below migrate button.<br>Make a backup of all files and database before migration and than click on "Migrate" button, this will run the migration functionality.', 'italystrap'),
esc_attr(get_option('template')),
esc_attr(get_option('stylesheet'))
\__('Migration page for ItalyStrap theme framework', 'italystrap'),
\__('Before upgrading to new version of the ItalyStrap theme framework (4.x) you need to migrate the old settings and rename the old directory of the theme to the new format "italystrap", update the style.css in your child theme to point to the correct parent directory and update the option "template" to the new format name.<br>To do so you can use the below migrate button.<br>Make a backup of all files and database before migration and than click on "Migrate" button, this will run the migration functionality.', 'italystrap'),
\esc_attr(\get_option('template')),
\esc_attr(\get_option('stylesheet'))
);

echo "<h3>Directory founded</h3>";
echo "<h3>Themes founded</h3>";

foreach (search_theme_directories() as $key => $value) {
foreach ((array)search_theme_directories() as $key => $value) {
echo "<pre>";
print_r($key);
echo PHP_EOL;
print_r($value);
echo "</pre>";
}
// wp_maintenance();

if (! isset($_POST['submit'])) {
return null;
}
// if (! isset($_POST['submit'])) {
// return null;
// }
// $old_data = (array) get_option('italystrap_theme_settings');
// \d($old_data);
//
//
// $new_options = get_option('italystrap_settings');
// \d($new_options);



// activate maintenance mode with wordpress function

$this->convert_data();
$this->upgrade_parent();
// $this->convert_data();
// $this->upgrade_parent();
}

/**
Expand All @@ -51,7 +64,8 @@ public function convert_data()
$settings_converter = new SettingsMigration();


$old_data = (array) get_option('italystrap_theme_settings');
$old_data = (array)get_option('italystrap_theme_settings');

$pattern = [
// 'old' => 'new',
'default_404' => 'default_404',
Expand All @@ -61,11 +75,15 @@ public function convert_data()
$settings_converter->dataToThemeMod($pattern, $old_data);


$pattern = ['favicon' => 'site_icon'];
$pattern = [
'favicon' => 'site_icon'
];
$settings_converter->dataToOption($pattern, $old_data);


$pattern = ['analytics' => 'google_analytics_id'];
$pattern = [
'analytics' => 'google_analytics_id'
];
$new_options = get_option('italystrap_settings');

$settings_converter->dataToOptions($pattern, $old_data, $new_options, 'italystrap_settings');
Expand Down Expand Up @@ -110,6 +128,7 @@ public function upgrade_parent()
*/
$this->rename->rename($old_parent_dir, $new_parent_dir);

//\switch_theme();
/**
* Then update option 'template'
*/
Expand Down
20 changes: 20 additions & 0 deletions src/Migrations/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace ItalyStrap\Migrations;

class Module
{
public function __invoke(): array
{
return [
'dependencies' => [
'aliases' => [
],
'sharing' => [
],
]
];
}
}
Loading