first commit
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
abstract class Brizy_Admin_Migrations_AbstractStorage {
|
||||
|
||||
const KEY = 'brizy-migrations';
|
||||
|
||||
/**
|
||||
* @var Brizy_Admin_Migrations_MigrationInterface[]
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* Brizy_Admin_Migations_AbstractStorage constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->data = array();
|
||||
$this->loadData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save run migrations
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function storeData();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function loadData();
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function save() {
|
||||
$this->storeData();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Brizy_Admin_Migrations_MigrationInterface $migration
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addMigration( Brizy_Admin_Migrations_MigrationInterface $migration ) {
|
||||
|
||||
if ( ! $this->hasMigration( $migration ) ) {
|
||||
$this->data[] = $migration;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @@return Brizy_Admin_Migrations_MigrationInterface[]
|
||||
*/
|
||||
public function getMigrations() {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Brizy_Admin_Migrations_MigrationInterface $amigratoin
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasMigration( Brizy_Admin_Migrations_MigrationInterface $amigratoin ) {
|
||||
$aMigrationClass = get_class( $amigratoin );
|
||||
foreach ( $this->data as $migration ) {
|
||||
if ( get_class( $migration ) == $aMigrationClass ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Brizy_Admin_Migrations_MigrationInterface|mixed
|
||||
*/
|
||||
public function latestMigration() {
|
||||
return end( $this->data );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
class Brizy_Admin_Migrations_AttachmentUidMigration implements Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
/**
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion() {
|
||||
return '2.3.21';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function execute() {
|
||||
|
||||
try {
|
||||
global $wpdb;
|
||||
$invalidAttachments = $wpdb->get_results(
|
||||
"SELECT
|
||||
p.ID as post_id,
|
||||
'brizy_attachment_uid' as meta_key,
|
||||
wp.meta_value as meta_value
|
||||
FROM {$wpdb->posts} p
|
||||
JOIN {$wpdb->postmeta} wp on p.ID = wp.post_id and wp.meta_key='brizy_post_uid'
|
||||
LEFT JOIN {$wpdb->postmeta} wp2 on p.ID = wp2.post_id and wp2.meta_key='brizy_attachment_uid'
|
||||
WHERE post_type='attachment' and wp2.meta_value is NULL", ARRAY_A );
|
||||
|
||||
if ( is_array( $invalidAttachments ) ) {
|
||||
foreach ( $invalidAttachments as $id => $insertData ) {
|
||||
$wpdb->insert($wpdb->postmeta,$insertData);
|
||||
}
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
class Brizy_Admin_Migrations_BlockPostTitleMigration implements Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
/**
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion() {
|
||||
return '1.0.82';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function execute() {
|
||||
|
||||
try {
|
||||
global $wpdb;
|
||||
$invalidBlocks = $wpdb->get_results(
|
||||
"SELECT p.ID, p.post_title FROM {$wpdb->posts} p
|
||||
WHERE p.post_type='brizy-global-block' OR p.post_type='brizy-saved-block'" );
|
||||
|
||||
if ( is_array( $invalidBlocks ) ) {
|
||||
foreach ( $invalidBlocks as $id => $block ) {
|
||||
if ( $block->post_title != '' ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = md5( time() . $id );
|
||||
$wpdb->query(
|
||||
$wpdb->prepare( "UPDATE {$wpdb->posts}
|
||||
SET `post_title` = %s, `post_name` = %s
|
||||
WHERE ID=%d ", array( $name, $name, $block->ID ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
class Brizy_Admin_Migrations_CleanInvalidBlocksMigration implements Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion() {
|
||||
return '1.0.74';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function execute() {
|
||||
|
||||
// disable this migration because of suspected data loss
|
||||
return;
|
||||
}
|
||||
|
||||
public function getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
class Brizy_Admin_Migrations_CleanLogsMigration implements Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion() {
|
||||
return '1.0.93';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute() {
|
||||
|
||||
try {
|
||||
Brizy_Logger::clean();
|
||||
} catch ( Exception $e ) {
|
||||
Brizy_Logger::instance()->critical( 'Filed migration Brizy_Admin_Migrations_CleanLogsMigration', [] );
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function getPriority() {
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Brizy_Admin_Migrations_DeleteTemplateRulesMigration implements Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
/**
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion() {
|
||||
return '2.0.13';
|
||||
}
|
||||
|
||||
/**
|
||||
* Run this method when upgrading.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function execute() {
|
||||
try {
|
||||
global $wpdb;
|
||||
$wpdb->query( "DELETE m FROM `{$wpdb->prefix}postmeta` m
|
||||
JOIN `{$wpdb->prefix}posts` p ON p.id=m.post_id and p.post_type NOT IN ('brizy-template','revision')
|
||||
WHERE meta_key='brizy-rules'" );
|
||||
} catch ( Exception $e ) {
|
||||
Brizy_Logger::instance()->critical( 'Filed migration Brizy_Admin_Migrations_DeletetemplateRulesMigration', [] );
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
class Brizy_Admin_Migrations_FixGlobalsToDataMigration implements Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
use Brizy_Admin_Migrations_PostsTrait;
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion() {
|
||||
return '1.0.97';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute() {
|
||||
|
||||
try {
|
||||
$projectPost = $this->getProjectPost();
|
||||
|
||||
if ( ! $projectPost ) {
|
||||
Brizy_Logger::instance()->critical( 'Filed migration Brizy_Admin_Migrations_FixGlobalsToDataMigration. We did not found any projects.', [] );
|
||||
return;
|
||||
}
|
||||
|
||||
$storage = Brizy_Editor_Storage_Project::instance( $projectPost->ID );
|
||||
|
||||
if ( $data = $storage->get( 'data', false ) ) {
|
||||
update_post_meta( $projectPost->ID, 'brizy-bk-' . get_class( $this ) . '-' . $this->getVersion(), $storage->get_storage() );
|
||||
|
||||
$beforeMergeGlobals = json_decode( base64_decode( $data ) );
|
||||
$editorBuildPath = Brizy_Editor_UrlBuilder::editor_build_path();
|
||||
|
||||
$context = new \Brizy\DataToProjectContext( $beforeMergeGlobals, $editorBuildPath );
|
||||
$projectMigration = new \Brizy\FixDataToProjectTransformer();
|
||||
$mergedGlobals = $projectMigration->execute( $context );
|
||||
$storage->set( 'data', base64_encode( json_encode( $mergedGlobals ) ) );
|
||||
}
|
||||
|
||||
} catch ( Exception $e ) {
|
||||
Brizy_Logger::instance()->critical( 'Filed migration Brizy_Admin_Migrations_GlobalsToDataMigration', [ $e ] );
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function getPriority() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
class Brizy_Admin_Migrations_FormSerializationMigration implements Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
/**
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion() {
|
||||
return '1.0.65';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|mixed|WP_Error
|
||||
* @throws Brizy_Editor_Exceptions_NotFound
|
||||
*/
|
||||
public function execute() {
|
||||
|
||||
if ( $this->wasExecuted() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$totalCount = $wpdb->get_var( "SELECT count(*) FROM {$wpdb->postmeta} WHERE meta_key='brizy-project'" );
|
||||
$offset = 0;
|
||||
$count = 20;
|
||||
|
||||
while ( $offset < $totalCount ) {
|
||||
$result = @mysqli_query( $wpdb->dbh, "SELECT meta_id,post_id,meta_value FROM {$wpdb->postmeta} WHERE meta_key='brizy-project' LIMIT {$offset}, {$count}" );
|
||||
|
||||
if ( $result ) {
|
||||
if ( $statement = mysqli_prepare( $wpdb->dbh, "UPDATE {$wpdb->postmeta} SET meta_value=? WHERE meta_id=? and post_id=? and meta_key='brizy-project'" ) ) {
|
||||
while ( ( $row = @mysqli_fetch_array( $result, 1 ) ) ) {
|
||||
// do stuff here for each result ...
|
||||
|
||||
$projectData = maybe_unserialize( $row['meta_value'] );
|
||||
$meta_id = (int) $row['meta_id'];
|
||||
$post_id = (int) $row['post_id'];
|
||||
|
||||
if ( isset( $projectData['forms'] ) ) {
|
||||
foreach ( $projectData['forms'] as $id => $form ) {
|
||||
if ( $form instanceof Brizy_Editor_Forms_Form ) {
|
||||
$projectData['forms'][ $id ] = $form->convertToOptionValue();
|
||||
} elseif ( ! is_null( $form ) ) {
|
||||
$projectData['forms'][ $id ] = $form;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$projectData = maybe_serialize( $projectData );
|
||||
|
||||
mysqli_stmt_bind_param( $statement, 'sii', $projectData, $meta_id, $post_id );
|
||||
mysqli_stmt_execute( $statement );
|
||||
}
|
||||
mysqli_stmt_close( $statement );
|
||||
}
|
||||
@mysqli_free_result( $result );
|
||||
}
|
||||
|
||||
$offset += 20;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function wasExecuted() {
|
||||
$storage = new Brizy_Admin_Migrations_GlobalStorage();
|
||||
$migrations = $storage->getMigrations();
|
||||
|
||||
foreach ( $migrations as $migration ) {
|
||||
if ( get_class( $migration ) == get_class( $this ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
class Brizy_Admin_Migrations_GlobalBlocksToCustomPostMigration implements Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
use Brizy_Admin_Migrations_PostsTrait;
|
||||
|
||||
/**
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion() {
|
||||
return '1.0.70';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|mixed|WP_Error
|
||||
* @throws Brizy_Editor_Exceptions_NotFound
|
||||
*/
|
||||
public function execute() {
|
||||
|
||||
$projectPost = $this->getProjectPost();
|
||||
|
||||
if ( ! $projectPost ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$projectStorage = Brizy_Editor_Storage_Project::instance( $projectPost->ID );
|
||||
$postMigrationStorage = new Brizy_Admin_Migrations_PostStorage( $projectPost->ID );
|
||||
$globals = json_decode( base64_decode( $projectStorage->get( 'globals', false ) ) );
|
||||
|
||||
if ( is_null($globals) || ! isset( $globals->project ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $globals || ( isset( $globals->project ) && empty( $globals->project ) ) ) {
|
||||
$projectStorage->set( 'globals', base64_encode( json_encode( (object) array() ) ) );
|
||||
$postMigrationStorage->addMigration( $this )->save();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $globals->project->globalBlocks ) ) {
|
||||
foreach ( get_object_vars( $globals->project->globalBlocks ) as $uid => $data ) {
|
||||
|
||||
$post = wp_insert_post( array(
|
||||
'post_status' => 'publish',
|
||||
'post_type' => Brizy_Admin_Blocks_Main::CP_GLOBAL
|
||||
) );
|
||||
|
||||
if ( $post ) {
|
||||
$brizyPost = Brizy_Editor_Block::get( $post, $uid );
|
||||
$brizyPost->set_editor_data( json_encode( $data ) );
|
||||
$brizyPost->set_uses_editor( true );
|
||||
$brizyPost->set_needs_compile( true );
|
||||
$brizyPost->saveStorage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $globals->project->savedBlocks ) ) {
|
||||
foreach ( $globals->project->savedBlocks as $data ) {
|
||||
|
||||
$post = wp_insert_post( array(
|
||||
'post_status' => 'publish',
|
||||
'post_type' => Brizy_Admin_Blocks_Main::CP_SAVED
|
||||
) );
|
||||
|
||||
if ( $post ) {
|
||||
$brizyPost = Brizy_Editor_Block::get( $post );
|
||||
$brizyPost->set_editor_data( json_encode( $data ) );
|
||||
$brizyPost->set_uses_editor( true );
|
||||
$brizyPost->set_needs_compile( true );
|
||||
$brizyPost->saveStorage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_post_meta( $projectPost->ID, 'brizy-bk-' . get_class( $this ) . '-' . $this->getVersion(), $globals );
|
||||
|
||||
unset( $globals->project->globalBlocks );
|
||||
unset( $globals->project->savedBlocks );
|
||||
|
||||
$projectStorage->set( 'globals', base64_encode( json_encode( $globals->project ) ) );
|
||||
$postMigrationStorage->addMigration( $this )->save();
|
||||
}
|
||||
|
||||
}
|
||||
28
wp-content/plugins/brizy/admin/migrations/global-storage.php
Normal file
28
wp-content/plugins/brizy/admin/migrations/global-storage.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
class Brizy_Admin_Migrations_GlobalStorage extends Brizy_Admin_Migrations_AbstractStorage {
|
||||
|
||||
/**
|
||||
* Save run migrations
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function storeData() {
|
||||
update_option( Brizy_Admin_Migrations_AbstractStorage::KEY, $this->data );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|void
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function loadData() {
|
||||
$this->data = get_option( Brizy_Admin_Migrations_AbstractStorage::KEY, array() );
|
||||
|
||||
|
||||
foreach ( $this->data as $i => $migration ) {
|
||||
if ( $migration instanceof __PHP_Incomplete_Class ) {
|
||||
throw new Brizy_Admin_Migrations_UpgradeRequiredException( 'Please update the plugin to the latest version' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
class Brizy_Admin_Migrations_GlobalVersionsMigration implements Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
use Brizy_Admin_Migrations_PostsTrait;
|
||||
|
||||
/**
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion() {
|
||||
return '1.0.45';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|mixed|WP_Error
|
||||
* @throws Brizy_Editor_Exceptions_NotFound
|
||||
*/
|
||||
public function execute() {
|
||||
|
||||
try {
|
||||
|
||||
$projectPost = $this->getProjectPost();
|
||||
|
||||
if ( ! $projectPost ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$projectStorage = Brizy_Editor_Storage_Project::instance( $projectPost->ID );
|
||||
|
||||
$pluginVersion = $projectStorage->get( 'pluginVersion', false );
|
||||
|
||||
if ( ! $pluginVersion ) {
|
||||
// this is going to fix the plugin and editor version
|
||||
$projectStorage->set( 'pluginVersion', BRIZY_VERSION );
|
||||
$projectStorage->set( 'editorVersion', BRIZY_EDITOR_VERSION );
|
||||
$projectStorage->delete( 'version' );
|
||||
}
|
||||
|
||||
} catch ( Exception $e ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
use \Brizy\DataToProjectContext;
|
||||
use \Brizy\DataToProjectTransformer;
|
||||
|
||||
class Brizy_Admin_Migrations_GlobalsToDataMigration implements Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
use Brizy_Admin_Migrations_PostsTrait;
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion() {
|
||||
return '1.0.76';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute() {
|
||||
|
||||
try {
|
||||
$projectPost = $this->getProjectPost();
|
||||
|
||||
if ( ! $projectPost ) {
|
||||
Brizy_Logger::instance()->critical( 'Filed migration Brizy_Admin_Migrations_GlobalsToDataMigration. We did not found any projects.', [] );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$storage = Brizy_Editor_Storage_Project::instance( $projectPost->ID );
|
||||
|
||||
if ( $globals = $storage->get( 'globals', false ) ) {
|
||||
update_post_meta( $projectPost->ID, 'brizy-bk-' . get_class( $this ) . '-' . $this->getVersion(), $storage->get_storage() );
|
||||
|
||||
$beforeMergeGlobals = json_decode( base64_decode( $globals ) );
|
||||
$editorBuildPath = Brizy_Editor_UrlBuilder::editor_build_path();
|
||||
|
||||
$context = new DataToProjectContext( $beforeMergeGlobals, $editorBuildPath );
|
||||
$projectMigration = new DataToProjectTransformer();
|
||||
$mergedGlobals = $projectMigration->execute( $context );
|
||||
$storage->set( 'data', base64_encode( json_encode( $mergedGlobals ) ) );
|
||||
$storage->delete( 'globals' );
|
||||
}
|
||||
|
||||
} catch ( Exception $e ) {
|
||||
Brizy_Logger::instance()->critical( 'Filed migration Brizy_Admin_Migrations_GlobalsToDataMigration', [ $e ] );
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function getPriority() {
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
interface Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion();
|
||||
|
||||
/**
|
||||
* Run this method when upgrading.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function execute();
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPriority();
|
||||
|
||||
}
|
||||
30
wp-content/plugins/brizy/admin/migrations/null-migration.php
Normal file
30
wp-content/plugins/brizy/admin/migrations/null-migration.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Brizy_Admin_Migrations_NullMigration implements Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
/**
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion() {
|
||||
return '0.0.1';
|
||||
}
|
||||
|
||||
/**
|
||||
* Run this method when upgrading.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function execute() {
|
||||
// this is a null migration
|
||||
}
|
||||
}
|
||||
38
wp-content/plugins/brizy/admin/migrations/post-storage.php
Normal file
38
wp-content/plugins/brizy/admin/migrations/post-storage.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Brizy_Admin_Migrations_PostStorage extends Brizy_Admin_Migrations_AbstractStorage {
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $postId;
|
||||
|
||||
/**
|
||||
* Brizy_Admin_Migations_PostStorage constructor.
|
||||
*
|
||||
* @param int $postId
|
||||
*/
|
||||
public function __construct( $postId ) {
|
||||
$this->postId = (int) $postId;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save run migrations
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function storeData() {
|
||||
update_post_meta( $this->postId, Brizy_Admin_Migrations_AbstractStorage::KEY, $this->data );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
protected function loadData() {
|
||||
$get_post_meta = get_post_meta( $this->postId, Brizy_Admin_Migrations_AbstractStorage::KEY, true );
|
||||
$this->data = is_array( $get_post_meta ) ? $get_post_meta : array();
|
||||
}
|
||||
}
|
||||
159
wp-content/plugins/brizy/admin/migrations/posts-trait.php
Normal file
159
wp-content/plugins/brizy/admin/migrations/posts-trait.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
trait Brizy_Admin_Migrations_PostsTrait {
|
||||
|
||||
private static $project;
|
||||
|
||||
/**
|
||||
* @return |null
|
||||
*/
|
||||
public function getProjectPost() {
|
||||
global $wpdb;
|
||||
|
||||
if ( self::$project ) {
|
||||
return self::$project;
|
||||
}
|
||||
|
||||
$row = $wpdb->get_results(
|
||||
$wpdb->prepare( "SELECT * FROM {$wpdb->posts} p
|
||||
WHERE p.post_type = %s and p.post_status='publish'
|
||||
ORDER BY ID DESC LIMIT 1 ", Brizy_Editor_Project::BRIZY_PROJECT ),
|
||||
OBJECT
|
||||
);
|
||||
|
||||
$projectPost = null;
|
||||
|
||||
if ( isset( $row[0] ) ) {
|
||||
return self::$project = $row[0];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get posts and meta
|
||||
*/
|
||||
public function get_posts_and_meta() {
|
||||
global $wpdb;
|
||||
|
||||
// query all posts (all post_type, all post_status) that have meta_key = 'brizy' and is not 'revision'
|
||||
return $wpdb->get_results( "
|
||||
SELECT p.ID, pm.meta_value FROM {$wpdb->postmeta} pm
|
||||
LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id
|
||||
WHERE pm.meta_key = 'brizy'
|
||||
AND p.post_type != 'revision'
|
||||
AND p.post_type != 'attachment'
|
||||
" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Globals posts
|
||||
*/
|
||||
public function get_globals_posts() {
|
||||
global $wpdb;
|
||||
|
||||
// query all global posts
|
||||
return $wpdb->get_results( "
|
||||
SELECT p.ID, pm.meta_value FROM {$wpdb->postmeta} pm
|
||||
LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id
|
||||
WHERE pm.meta_key = 'brizy-project'
|
||||
AND p.post_type = 'brizy-project'
|
||||
" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse array of shortcodes recursive
|
||||
*/
|
||||
public function array_walk_recursive_and_delete( array &$array, callable $callback, $userdata = null ) {
|
||||
foreach ( $array as $key => &$value ) {
|
||||
if ( is_array( $value ) ) {
|
||||
$value = $this->array_walk_recursive_and_delete( $value, $callback, $userdata );
|
||||
// if is shortcode parse recursive
|
||||
if ( isset( $value['type'], $value['value'] ) ) {
|
||||
$this->parse_shortcodes( $value );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate post
|
||||
*/
|
||||
public function migrate_post( $json_value ) {
|
||||
$old_arr = json_decode( $json_value, true );
|
||||
if ( is_null( $old_arr ) ) {
|
||||
return $json_value;
|
||||
}
|
||||
|
||||
$new_arr = $this->array_walk_recursive_and_delete( $old_arr, function ( $value, $key ) {
|
||||
if ( is_array( $value ) ) {
|
||||
return empty( $value );
|
||||
}
|
||||
|
||||
if ( isset( $value['type'], $value['value'] ) ) {
|
||||
// if is shortcode return true
|
||||
return true;
|
||||
}
|
||||
} );
|
||||
|
||||
return json_encode( $new_arr );
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse shortcodes
|
||||
*/
|
||||
public function parse_shortcodes( array &$array ) {
|
||||
// rewrite this function in your class
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset mobile keys
|
||||
*/
|
||||
public function unset_prefixed_keys( array &$array, $atts = array() ) {
|
||||
// merge with default $atts
|
||||
$atts = array_merge(
|
||||
array(
|
||||
"shortcode" => "",
|
||||
"delete_keys" => array(),
|
||||
"dependent_keys" => false,
|
||||
"key_prefix" => "mobile"
|
||||
),
|
||||
$atts
|
||||
);
|
||||
|
||||
if ( empty( $atts['shortcode'] ) && empty( $atts['delete_keys'] ) ) {
|
||||
return $array;
|
||||
}
|
||||
|
||||
if ( $atts['shortcode'] == $array['type'] ) {
|
||||
$keys_to_remove = array();
|
||||
foreach ( $atts['delete_keys'] as $key_to_delete ) {
|
||||
// replace "prefix" with empty string then make first letter lowercase
|
||||
$key = lcfirst( str_replace( $atts['key_prefix'], "", $key_to_delete ) );
|
||||
if ( isset( $array['value'][ $key ], $array['value'][ $key_to_delete ] ) && $array['value'][ $key ] === $array['value'][ $key_to_delete ] ) {
|
||||
$keys_to_remove[] = $key_to_delete;
|
||||
}
|
||||
}
|
||||
|
||||
// !Atention if the number of keys to delete are not the same to not delete
|
||||
if ( $atts['dependent_keys'] && count( $keys_to_remove ) != count( $atts['delete_keys'] ) ) {
|
||||
$keys_to_remove = array();
|
||||
}
|
||||
|
||||
// remove keys
|
||||
if ( ! empty( $keys_to_remove ) ) {
|
||||
foreach ( $keys_to_remove as $key_to_remove ) {
|
||||
unset( $array['value'][ $key_to_remove ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
class Brizy_Admin_Migrations_ProjectToCustomPostMigration implements Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
|
||||
/**
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion() {
|
||||
return '1.0.30';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|mixed|WP_Error
|
||||
* @throws Brizy_Editor_Exceptions_NotFound
|
||||
*/
|
||||
public function execute() {
|
||||
|
||||
if ( $this->isGlobalProjectCreated() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$storage = Brizy_Editor_Storage_Common::instance();
|
||||
$projectData = $storage->get( Brizy_Editor_Project::BRIZY_PROJECT, false );
|
||||
|
||||
if ( is_array( $projectData ) ) {
|
||||
$projectData = unserialize( $projectData['api_project'] );
|
||||
} elseif ( $projectData instanceof Brizy_Editor_Project ) {
|
||||
$projectData = $projectData->getApiProject()->get_data();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( base64_encode( base64_decode( $projectData['globals'] ) ) !== $projectData['globals'] ) {
|
||||
$projectData['globals'] = base64_encode( $projectData['globals'] );
|
||||
}
|
||||
|
||||
$post_id = wp_insert_post( array(
|
||||
'post_type' => Brizy_Editor_Project::BRIZY_PROJECT,
|
||||
'post_title' => 'Brizy Project',
|
||||
'post_status' => 'publish',
|
||||
'comment_status' => 'closed',
|
||||
'ping_status' => 'closed'
|
||||
) );
|
||||
|
||||
$newProjectData = array(
|
||||
'id' => $projectData['id'],
|
||||
'title' => $projectData['title'],
|
||||
'globals' => $projectData['globals'],
|
||||
'name' => $projectData['name'],
|
||||
'user' => $projectData['user'],
|
||||
'template' => $projectData['template'],
|
||||
'created' => $projectData['created'],
|
||||
'updated' => $projectData['updated'],
|
||||
'languages' => $projectData['signature'],
|
||||
'version' => $projectData['version'],
|
||||
'signature' => $projectData['signature'],
|
||||
);
|
||||
|
||||
$storage = Brizy_Editor_Storage_Project::instance( $post_id );
|
||||
$storage->loadStorage( $newProjectData );
|
||||
|
||||
return $post_id;
|
||||
|
||||
}
|
||||
|
||||
public function isGlobalProjectCreated() {
|
||||
global $wpdb;
|
||||
|
||||
$projectId = $wpdb->get_var( $wpdb->prepare( " SELECT ID FROM {$wpdb->posts} WHERE post_type=%s", Brizy_Editor_Project::BRIZY_PROJECT ) );
|
||||
|
||||
return ! is_null( $projectId ) && $projectId > 0;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Brizy_Admin_Migrations_RulesMigration implements Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
/**
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion() {
|
||||
return '1.0.54';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|mixed|WP_Error
|
||||
* @throws Brizy_Editor_Exceptions_NotFound
|
||||
*/
|
||||
public function execute() {
|
||||
|
||||
$templateIds = $this->getTemplateIds();
|
||||
|
||||
foreach ( $templateIds as $templateId ) {
|
||||
$data = get_post_meta( (int) $templateId->post_id, 'brizy-template-rules', true );
|
||||
add_post_meta( (int) $templateId->post_id, 'brizy-bk-' . get_class( $this ) . '-' . $this->getVersion(), $data );
|
||||
add_post_meta( (int) $templateId->post_id, 'brizy-rules', $data );
|
||||
delete_post_meta( (int) $templateId->post_id, 'brizy-template-rules' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get posts and meta
|
||||
*/
|
||||
public function getTemplateIds() {
|
||||
global $wpdb;
|
||||
|
||||
// query all posts (all post_type, all post_status) that have meta_key = 'brizy' and is not 'revision'
|
||||
return $wpdb->get_results( "SELECT pm.post_id FROM {$wpdb->postmeta} pm WHERE pm.meta_key = 'brizy-template-rules'" );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Brizy_Admin_Migrations_ScreenshotMigration implements Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
/**
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion() {
|
||||
return '1.0.123';
|
||||
}
|
||||
|
||||
/**
|
||||
* Run this method when upgrading.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function execute() {
|
||||
// this is a null migration
|
||||
|
||||
global $wpdb;
|
||||
|
||||
if ( ! class_exists( 'Brizy\BlockScreenshotContext' ) || ! class_exists( 'Brizy\BlockScreenshotTransformer' ) ) {
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
$entities = $wpdb->get_results(
|
||||
"SELECT
|
||||
p.id as ID
|
||||
FROM {$wpdb->posts} p
|
||||
LEFT JOIN {$wpdb->posts} pp ON pp.id=p.post_parent
|
||||
WHERE IF(pp.post_type IS NOT NULL,pp.post_type,p.post_type) in ('brizy-global-block','brizy-saved-block')
|
||||
|
||||
" );
|
||||
|
||||
foreach ( $entities as $row ) {
|
||||
if ( metadata_exists( 'post', $row->ID, Brizy_Editor_Block::BRIZY_META ) ) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$this->migrateEntity( $row->ID );
|
||||
} catch ( Brizy_Editor_Exceptions_NotFound $e ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $postId
|
||||
*/
|
||||
private function migrateEntity( $postId ) {
|
||||
$storage = Brizy_Editor_Storage_Post::instance( $postId );
|
||||
$storage_post = $storage->get( Brizy_Editor_Post::BRIZY_POST, true );
|
||||
|
||||
if ( ! isset( $storage_post['editor_data'] ) ) {
|
||||
throw new Exception( 'editor_data not found on block: ' . $postId );
|
||||
}
|
||||
|
||||
if ( ( $dataJson = base64_decode( $storage_post['editor_data'], true ) ) === false ) {
|
||||
$dataJson = $storage_post['editor_data'];
|
||||
}
|
||||
|
||||
$dataObject = json_decode( $dataJson );
|
||||
|
||||
$transformerContext = new \Brizy\BlockScreenshotContext( $dataObject );
|
||||
$transformer = new \Brizy\BlockScreenshotTransformer();
|
||||
$transformer->execute( $transformerContext );
|
||||
|
||||
|
||||
$metaJson = json_encode( $transformerContext->getMeta() );
|
||||
update_metadata( 'post', $postId, Brizy_Editor_Block::BRIZY_META, $metaJson );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,448 @@
|
||||
<?php
|
||||
|
||||
class Brizy_Admin_Migrations_ShortcodesMobileOneMigration implements Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
use Brizy_Admin_Migrations_PostsTrait;
|
||||
|
||||
/**
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion() {
|
||||
return '1.0.39';
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the migration
|
||||
*/
|
||||
public function execute() {
|
||||
$this->posts_migration();
|
||||
$this->globals_migration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts migration
|
||||
*/
|
||||
public function posts_migration() {
|
||||
$result = $this->get_posts_and_meta();
|
||||
$class = __CLASS__;
|
||||
|
||||
// parse each post
|
||||
foreach ( $result as $item ) {
|
||||
$postMigrationStorage = new Brizy_Admin_Migrations_PostStorage( $item->ID );
|
||||
if ( $postMigrationStorage->hasMigration($this) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$json_value = null;
|
||||
$instance = Brizy_Editor_Storage_Post::instance($item->ID);
|
||||
$storage = $instance->get_storage();
|
||||
$old_meta = $instance->get(Brizy_Editor_Post::BRIZY_POST, false);
|
||||
|
||||
if ( is_array($old_meta) ) {
|
||||
$json_value = base64_decode($old_meta['editor_data']);
|
||||
}
|
||||
elseif( is_object($old_meta) ) {
|
||||
$json_value = $old_meta->get_editor_data();
|
||||
}
|
||||
|
||||
if( !is_null($json_value) ) {
|
||||
// make a backup to previous version
|
||||
update_post_meta($item->ID, 'brizy-bk-'.$class.'-'.$this->getVersion(), $storage);
|
||||
|
||||
// migrate post
|
||||
$new_json = $this->migrate_post($json_value);
|
||||
|
||||
// set the changed value in DB
|
||||
if ( is_array($old_meta) ) {
|
||||
$old_meta['editor_data'] = base64_encode($new_json);
|
||||
}
|
||||
elseif( is_object($old_meta) ) {
|
||||
$old_meta->set_editor_data($new_json);
|
||||
}
|
||||
$instance->set(Brizy_Editor_Post::BRIZY_POST, $old_meta);
|
||||
|
||||
// set that migration was successful executed
|
||||
$postMigrationStorage->addMigration($this)->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Globals migration
|
||||
*/
|
||||
public function globals_migration() {
|
||||
$class = __CLASS__;
|
||||
$result = $this->get_globals_posts();
|
||||
foreach ($result as $item) {
|
||||
$postMigrationStorage = new Brizy_Admin_Migrations_PostStorage( $item->ID );
|
||||
if ( $postMigrationStorage->hasMigration($this) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$instance = Brizy_Editor_Storage_Project::instance( $item->ID );
|
||||
$storage = $instance->get_storage();
|
||||
|
||||
if ( ! isset( $storage['globals'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$json_value = base64_decode($storage['globals']);
|
||||
|
||||
if( !is_null($json_value) ) {
|
||||
// make a backup to previous version
|
||||
update_post_meta($item->ID, 'brizy-bk-' . $class . '-' . $this->getVersion(), $storage);
|
||||
|
||||
// migrate post
|
||||
$new_json = $this->migrate_post($json_value);
|
||||
|
||||
// set the changed value in DB
|
||||
$storage['globals'] = base64_encode($new_json);
|
||||
$instance->loadStorage($storage);
|
||||
|
||||
// set that migration was successful executed
|
||||
$postMigrationStorage->addMigration($this)->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse shortcodes
|
||||
*/
|
||||
public function parse_shortcodes(array &$array) {
|
||||
// Line
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "Line",
|
||||
"delete_keys" => array(
|
||||
"mobileWidth",
|
||||
"mobileBorderWidth"
|
||||
)
|
||||
) );
|
||||
|
||||
// Spacer
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "Spacer",
|
||||
"delete_keys" => array(
|
||||
"mobileHeight"
|
||||
)
|
||||
) );
|
||||
|
||||
// Video
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "Video",
|
||||
"delete_keys" => array(
|
||||
"mobileSize",
|
||||
"mobileCoverImageWidth",
|
||||
"mobileCoverImageHeight"
|
||||
)
|
||||
) );
|
||||
|
||||
// EmbedCode
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "EmbedCode",
|
||||
"delete_keys" => array(
|
||||
"mobileWidth",
|
||||
"mobileHeight"
|
||||
)
|
||||
) );
|
||||
|
||||
// Map
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "Map",
|
||||
"delete_keys" => array(
|
||||
"mobileSize",
|
||||
"mobileHeight"
|
||||
)
|
||||
) );
|
||||
|
||||
// SoundCloud
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "SoundCloud",
|
||||
"delete_keys" => array(
|
||||
"mobileWidth",
|
||||
"mobileHeight"
|
||||
)
|
||||
) );
|
||||
|
||||
// Countdown
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "Countdown",
|
||||
"delete_keys" => array(
|
||||
"mobileWidth"
|
||||
)
|
||||
) );
|
||||
|
||||
// ProgressBar
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "ProgressBar",
|
||||
"delete_keys" => array(
|
||||
"mobileWidth",
|
||||
"mobileBorderRadius"
|
||||
)
|
||||
) );
|
||||
|
||||
// Wrapper
|
||||
$array = $this->mobile_migation_wrapper_align( $array, "Wrapper" );
|
||||
|
||||
// Cloneable
|
||||
$array = $this->mobile_migation_wrapper_align( $array, "Cloneable" );
|
||||
|
||||
// WOOCategories
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "WOOCategories",
|
||||
"delete_keys" => array(
|
||||
"mobileWidth"
|
||||
)
|
||||
) );
|
||||
|
||||
// WOOPages
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "WOOPages",
|
||||
"delete_keys" => array(
|
||||
"mobileWidth"
|
||||
)
|
||||
) );
|
||||
|
||||
// WOOProducts
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "WOOProducts",
|
||||
"delete_keys" => array(
|
||||
"mobileWidth"
|
||||
)
|
||||
) );
|
||||
|
||||
// WPSidebar
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "WPSidebar",
|
||||
"delete_keys" => array(
|
||||
"mobileWidth"
|
||||
)
|
||||
) );
|
||||
|
||||
// WPCustomShortcode
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "WPCustomShortcode",
|
||||
"delete_keys" => array(
|
||||
"mobileWidth"
|
||||
)
|
||||
) );
|
||||
|
||||
// WOOProductPage
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "WOOProductPage",
|
||||
"delete_keys" => array(
|
||||
"mobileWidth"
|
||||
)
|
||||
) );
|
||||
|
||||
// WPNavigation
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "WPNavigation",
|
||||
"delete_keys" => array(
|
||||
"mobileWidth",
|
||||
"mobileItemPadding"
|
||||
)
|
||||
) );
|
||||
|
||||
// Button
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "Button",
|
||||
"delete_keys" => array(
|
||||
"mobileBorderRadius"
|
||||
)
|
||||
) );
|
||||
|
||||
// Tabs
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "Tabs",
|
||||
"delete_keys" => array(
|
||||
"mobileHorizontalAlign"
|
||||
)
|
||||
) );
|
||||
|
||||
// Image
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "Image",
|
||||
"delete_keys" => array(
|
||||
"mobileResize",
|
||||
"mobileZoom",
|
||||
"mobileWidth",
|
||||
"mobileHeight"
|
||||
)
|
||||
) );
|
||||
|
||||
// Delete image position if all are equal
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "Image",
|
||||
"delete_keys" => array(
|
||||
"mobilePositionX",
|
||||
"mobilePositionY"
|
||||
),
|
||||
"dependent_keys" => true
|
||||
) );
|
||||
|
||||
// Form
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "Form",
|
||||
"delete_keys" => array(
|
||||
"mobileHorizontalAlign"
|
||||
)
|
||||
) );
|
||||
|
||||
// Form fields options
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "FormFields",
|
||||
"delete_keys" => array(
|
||||
"mobilePadding",
|
||||
"mobilePaddingRight",
|
||||
"mobilePaddingBottom",
|
||||
"mobilePaddingLeft",
|
||||
),
|
||||
"dependent_keys" => true
|
||||
) );
|
||||
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "FormFields",
|
||||
"delete_keys" => array(
|
||||
"mobileBorderRadius",
|
||||
"mobilePaddingTop" // top is used as zero from the default json
|
||||
)
|
||||
) );
|
||||
|
||||
// Form single field options
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "FormField",
|
||||
"delete_keys" => array(
|
||||
"mobileWidth",
|
||||
"mobileHeight"
|
||||
)
|
||||
) );
|
||||
|
||||
// Icon
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "Icon",
|
||||
"delete_keys" => array(
|
||||
"mobilePadding",
|
||||
"mobileBorderRadius"
|
||||
)
|
||||
) );
|
||||
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "Icon",
|
||||
"delete_keys" => array(
|
||||
"mobileSize",
|
||||
"mobileCustomSize"
|
||||
),
|
||||
"dependent_keys" => true
|
||||
) );
|
||||
|
||||
// Row
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "Row",
|
||||
"delete_keys" => array(
|
||||
"mobileMedia",
|
||||
"mobileBgImageWidth",
|
||||
"mobileBgImageHeight",
|
||||
"mobileBgImageSrc",
|
||||
"mobileBgColorHex",
|
||||
"mobileBgColorOpacity",
|
||||
"mobileBgColorPalette",
|
||||
"mobileBgMapZoom"
|
||||
)
|
||||
) );
|
||||
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "Row",
|
||||
"delete_keys" => array(
|
||||
"mobileBgPositionX",
|
||||
"mobileBgPositionY"
|
||||
),
|
||||
"dependent_keys" => true
|
||||
) );
|
||||
|
||||
// Column
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "Column",
|
||||
"delete_keys" => array(
|
||||
"mobileBgImageWidth",
|
||||
"mobileBgImageHeight",
|
||||
"mobileBgImageSrc",
|
||||
"mobileBgColorHex",
|
||||
"mobileBgColorOpacity",
|
||||
"mobileBgColorPalette"
|
||||
)
|
||||
) );
|
||||
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "Column",
|
||||
"delete_keys" => array(
|
||||
"mobileBgPositionX",
|
||||
"mobileBgPositionY"
|
||||
),
|
||||
"dependent_keys" => true
|
||||
) );
|
||||
|
||||
// Section
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "SectionItem",
|
||||
"delete_keys" => array(
|
||||
"mobileMedia",
|
||||
"mobileBgImageWidth",
|
||||
"mobileBgImageHeight",
|
||||
"mobileBgImageSrc",
|
||||
"mobileBgColorHex",
|
||||
"mobileBgColorOpacity",
|
||||
"mobileBgColorPalette",
|
||||
"mobileBgMapZoom"
|
||||
)
|
||||
) );
|
||||
|
||||
$array = $this->unset_prefixed_keys( $array, array(
|
||||
"shortcode" => "SectionItem",
|
||||
"delete_keys" => array(
|
||||
"mobileBgPositionX",
|
||||
"mobileBgPositionY"
|
||||
),
|
||||
"dependent_keys" => true
|
||||
) );
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Special Migration for Wrapper and Cloneable "align"
|
||||
*/
|
||||
public function mobile_migation_wrapper_align(array &$array, $shortcode = "") {
|
||||
if ( empty($shortcode) ) {
|
||||
return $array;
|
||||
}
|
||||
|
||||
if ( $shortcode == $array['type'] ) {
|
||||
if ( isset( $array['value']['horizontalAlign'], $array['value']['mobileHorizontalAlign'] ) && $array['value']['horizontalAlign'] === $array['value']['mobileHorizontalAlign'] )
|
||||
{
|
||||
unset( $array['value']['mobileHorizontalAlign'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
// !Attention this need only 1-time execution in JSON (to not apply to the same JSON 2 times)
|
||||
if ( isset( $array['value']['horizontalAlign'] )
|
||||
&& ( $array['value']['horizontalAlign'] !== "center" )
|
||||
&& !isset( $array['value']['mobileHorizontalAlign'] ) )
|
||||
{
|
||||
$array['value']['mobileHorizontalAlign'] = "center";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
class Brizy_Admin_Migrations_SiteSettingsMigration implements Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
/**
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion() {
|
||||
return '1.0.118';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|mixed|WP_Error
|
||||
* @throws Brizy_Editor_Exceptions_NotFound
|
||||
*/
|
||||
public function execute() {
|
||||
|
||||
delete_option('brizy-social-title');
|
||||
delete_option('brizy-social-description');
|
||||
delete_option('brizy-custom-css');
|
||||
delete_option('brizy-header-injection');
|
||||
delete_option('brizy-footer-injection');
|
||||
delete_option('brizy-social-thumbnail');
|
||||
delete_option('brizy-settings-favicon');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Brizy_Admin_Migrations_UpgradeRequiredException extends Exception {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Brizy_Admin_Migrations_UseEditorMigration implements Brizy_Admin_Migrations_MigrationInterface {
|
||||
|
||||
/**
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the version
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion() {
|
||||
return '2.2.6';
|
||||
}
|
||||
|
||||
/**
|
||||
* Run this method when upgrading.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function execute() {
|
||||
try {
|
||||
global $wpdb;
|
||||
|
||||
$brizyEnabled = Brizy_Editor_Constants::BRIZY_ENABLED;
|
||||
|
||||
$var = (int)$wpdb->get_var("SELECT count(meta_id) FROM {$wpdb->postmeta} WHERE meta_key='brizy_enabled'");
|
||||
|
||||
if($var > 0) return;
|
||||
|
||||
$wpdb->query( "INSERT INTO {$wpdb->postmeta} (post_id,meta_key,meta_value)
|
||||
SELECT post_id,'brizy_enabled',POSITION('\"brizy-use-brizy\";b:1;' IN meta_value)>0 FROM {$wpdb->postmeta} where meta_key='brizy'" );
|
||||
} catch ( Exception $e ) {
|
||||
Brizy_Logger::instance()->critical( 'Filed migration Brizy_Admin_Migrations_DeletetemplateRulesMigration', [] );
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user