BC Migration Documentation

MigrateReports

MigrateReports class.

Table of Contents

Properties

$instance  : MigrateReports|null
The single instance of the class.
$db  : object
The database instance for report data.
$upload_dir_path  : string
The path to the upload directory.

Methods

init()  : MigrateReports
Gets the single instance of the class.
migrate_data()  : array<int, mixed>
Migrates AI Tool data.
__construct()  : mixed
Constructor.
clean_files()  : array<string|int, string>
Clean up the given files.
db_entry_exists()  : bool
Checks if a db entry exists, given the first name, last name, and email.
get_files()  : array<string|int, string>
Get all the files in the bc-ai-tool-data directory.
insert_into_db()  : int|WP_Error
Inserts the given data into the database.
maybe_format_keys()  : array<string, mixed>
Converts the keys of the given array from camel case to snake case.
migrate_reports()  : array<int, string>|array<int, int>|false
Migrates the AI Tool reports from the JSON files to the database.
prepare_item_for_db()  : array<string, mixed>
Prepares the given report item for insertion into the database.
prepare_report_for_db()  : array<string|int, string>
Prepares the given report item for insertion into the database.

Properties

$upload_dir_path

The path to the upload directory.

private string $upload_dir_path

Methods

migrate_data()

Migrates AI Tool data.

public migrate_data() : array<int, mixed>

Finds all the files in the bc-ai-tool-data directory and migrates them to the database.

Return values
array<int, mixed>

An array of migrated data.

__construct()

Constructor.

private __construct() : mixed

Initializes the MigrateReports class by setting up the upload directory path and database instance for report data.

Tags
access

private

clean_files()

Clean up the given files.

private clean_files(array<string|int, string> $files) : array<string|int, string>
Parameters
$files : array<string|int, string>

The files to clean up.

Return values
array<string|int, string>

The cleaned up files.

db_entry_exists()

Checks if a db entry exists, given the first name, last name, and email.

private db_entry_exists(array<string, mixed> $data) : bool

If the data is not valid (e.g. empty or not set), this function will return true to indicate that the data should be skipped.

Parameters
$data : array<string, mixed>

The data to check for.

Return values
bool

True if the database entry exists, false otherwise.

get_files()

Get all the files in the bc-ai-tool-data directory.

private get_files() : array<string|int, string>

Finds all the files in the bc-ai-tool-data directory and returns them as an array. If the directory does not exist, or if there are no files with the name 'data-*', an empty array is returned.

Return values
array<string|int, string>

An array of file paths.

insert_into_db()

Inserts the given data into the database.

private insert_into_db(array<string, mixed> $data) : int|WP_Error

Attempts to insert the provided array of data into the database. If the insertion fails, a WP_Error object is returned indicating the failure. If successful, the ID of the inserted row is returned.

Parameters
$data : array<string, mixed>

The data to insert.

Return values
int|WP_Error

The ID of the inserted row, or a WP_Error object on failure.

maybe_format_keys()

Converts the keys of the given array from camel case to snake case.

private maybe_format_keys(array<string, mixed> $data) : array<string, mixed>
Parameters
$data : array<string, mixed>

The array with camel case keys.

Return values
array<string, mixed>

The array with keys converted to snake case.

migrate_reports()

Migrates the AI Tool reports from the JSON files to the database.

private migrate_reports(array<int, string> $files) : array<int, string>|array<int, int>|false
Parameters
$files : array<int, string>

Array of JSON files to be migrated.

Return values
array<int, string>|array<int, int>|false

Array of IDs of migrated reports.

prepare_item_for_db()

Prepares the given report item for insertion into the database.

private prepare_item_for_db(array<string, mixed> $item) : array<string, mixed>

Sets the created date to the current time if not provided. Converts the integrationCampaign2 key to report_url. Serializes the data if it isn't already.

Parameters
$item : array<string, mixed>

The report item to prepare.

Return values
array<string, mixed>

The prepared report item.

prepare_report_for_db()

Prepares the given report item for insertion into the database.

private prepare_report_for_db(string $file, string $app) : array<string|int, string>

The method will read the given file, convert the keys from camel case to snake case, prepare the item for the database by setting the created date to the current time if not provided, and then add the app name to the data and set the report_url to the boomi_link. If the job key exists, it is removed after being used to set the title. The boomi_link key is removed after being used to set the report_url.

Parameters
$file : string

The json file to read.

$app : string

The app name.

Return values
array<string|int, string>

The prepared report item.


        
On this page

Search results