# templately/trunk/modules/full-site-import/Runners/BaseRunner.php

Templately – Elementor &amp; Gutenberg Template Library: 6500+ Free &amp; Pro Ready Templates And Cloud!, version trunk. 133 lines.

- Page: https://pluginprobe.com/plugins/templately/trunk/code/modules/full-site-import/Runners/BaseRunner.php
- Raw: https://pluginprobe.com/plugins/templately/trunk/raw/modules/full-site-import/Runners/BaseRunner.php
- Modified: 2026-09-24T05:45:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/templately/trunk/code/modules/full-site-import/Runners/BaseRunner.php#L10-L20`.

```php
<?php

namespace Templately\Modules\FullSiteImport\Runners;

use Exception;
use Templately\Modules\ThemeBuilder\Factory\TemplateFactory;
use Templately\Modules\FullSiteImport\FullSiteImport;
use Templately\Modules\FullSiteImport\Import;
use Templately\Modules\FullSiteImport\Concerns\LogHelper;
use Templately\Modules\FullSiteImport\Utils\AIUtils;
use Templately\Modules\FullSiteImport\Utils\ImportHelper;
use Templately\Modules\FullSiteImport\Utils\Utils;
use Templately\Utils\Helper;

abstract class BaseRunner {
	use LogHelper;
	use Loop;

	const META_SESSION_KEY = '_templately_import_session_id';
	/**
	 * @var FullSiteImport
	 */
	protected $dev_mode;
	protected $origin;
	protected $platform;
	protected $manifest;
	protected $prv_dir;
	protected $dir_path;
	protected $session_id;
	/**
	 * @var array|mixed
	 */
	public $ai_page_ids = [];
	/**
	 * @var string|null
	 */
	public $process_id = null;

	/**
	 * @var ImportHelper
	 */
	protected $json;

	/**
	 * @var TemplateFactory
	 */
	protected $factory;

	/**
	 * @throws Exception
	 */
	public function __construct( $request_params ) {
		$this->dev_mode   = defined('TEMPLATELY_DEV') && TEMPLATELY_DEV;
		$this->origin     = $request_params['origin'];
		$this->prv_dir    = $request_params['prv_dir'];
		$this->dir_path   = $request_params['dir_path'];
		$this->manifest   = &$request_params['manifest'];
		$this->platform   = $this->manifest['platform'] ?? '';
		$this->session_id = $request_params['session_id'];


		$this->factory = new TemplateFactory( $this->platform );
		$this->json = Utils::get_json_helper( $this->platform );
		$this->json->session_id = $this->session_id;

		// Normalize once here so every runner sees the canonical
		// `type/sub_type => ['id',...]` shape. This value arrives from the import
		// FormData (a JSON string), session data, or the manifest, and consumers
		// index into it in ways that either throw or silently miss pages when the
		// shape differs. See AIUtils::normalize_ai_page_ids().
		$this->ai_page_ids = AIUtils::normalize_ai_page_ids( $request_params['ai_page_ids'] ?? [] );
		$this->process_id = $request_params['process_id'] ?? null;

		if ( empty( $this->platform ) ) {
			throw new Exception( __( 'Platform is not specified. Please try again after specifying the platform.', 'templately' ) );
		}
	}

	public function should_log(): bool {
		return true;
	}

	public function get_action(): string {
		return 'updateLog';
	}

	abstract public function get_name(): string;

	abstract public function get_label(): string;

	abstract public function should_run( $data, $imported_data = [] ): bool;

	abstract public function import( $data, $imported_data ): array;

	abstract public function log_message() : string;

	public function log( $progress = 0, $message = null, $action = null ) {
		if( ! $this->should_log() ) {
			return;
		}

		if( $message == null ) {
			$message = $this->log_message();
		}

		if( $action == null ) {
			$action = $this->get_action();
		}

		$this->sse_log( $this->get_name(), $message, min( $progress, 100 ), $action );
	}

	/**
	 * @throws Exception
	 */
	protected function throw($message, $code = 0) {
		if ($this->dev_mode) {
			Helper::log($message, 'fsi_error');
		}
		throw new Exception($message);
	}

	protected function is_ai_content($old_template_id ): bool {
		if(empty($this->process_id) || empty($this->ai_page_ids)){
			return false;
		}

		// $this->ai_page_ids is already normalized in the constructor, so this is
		// a plain flatten + strict membership test. It used to array_reduce with
		// 'array_merge', which throws a TypeError if any group value is a scalar.
		return AIUtils::is_ai_content($old_template_id, $this->ai_page_ids);
	}
}
```
