BC Migration Documentation

MigrateReports

MigrateReports class.

Table of Contents

Properties

$db  : object
The database instance for report data.
$instance  : object
The single instance of the class.
$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 data.
__construct()  : mixed
Constructor.
db_entry_exists()  : bool
Checks if a db entry exists, given the first name, last name, and email.
get_files()  : array<int, string>
Gets all the files in the bc-apiida 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 associative array from camel case to snake case.
migrate_reports()  : array<int, string>
Migrates the AI Tool reports from the JSON files to the database.

Properties

$instance

The single instance of the class.

protected static object $instance

$upload_dir_path

The path to the upload directory.

protected string $upload_dir_path

Methods

migrate_data()

Migrates data.

public migrate_data() : array<int, mixed>

Finds all the files in the bc-apiida directory and migrates them to the database.

Return values
array<int, mixed>

An array of migrated data.

__construct()

Constructor.

protected __construct() : mixed

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

Tags
access

protected

db_entry_exists()

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

protected db_entry_exists(array{first_name: string, last_name: string, email: string} $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{first_name: string, last_name: string, email: string}

The data to check for.

Return values
bool

True if the database entry exists, false otherwise.

get_files()

Gets all the files in the bc-apiida directory.

protected get_files() : array<int, string>

Finds all the files in the bc-apiida 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<int, string>

An array of file paths.

insert_into_db()

Inserts the given data into the database.

protected 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 associative array from camel case to snake case.

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

Utilizes the camel_to_snake function to transform each key in the array.

Parameters
$data : array<string, mixed>

The associative array with camel case keys to be transformed.

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.

protected migrate_reports(array<int, string> $files) : array<int, string>
Parameters
$files : array<int, string>

Array of JSON file paths to be migrated.

Return values
array<int, string>

Array of IDs of migrated reports.


        
On this page

Search results