HEX
Server: LiteSpeed
System: Linux melbournecleaninggroup 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: www-data (33)
PHP: 7.3.33-1+focal
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: /var/www/html/wp-content/plugins/brizy/admin/migrations/form-serialization-migration.php
<?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;
	}

}