BC Migration Documentation

MigrateLikes

MigrateLikes class.

Table of Contents

Properties

$instance  : MigrateLikes|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()  : MigrateLikes
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()  : object|false
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_or_update_db()  : int|WP_Error
Inserts or updates 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_likes()  : array<string|int, int>|false
Migrates AI Tool like data from a set of JSON files to the database.
prepare_data_for_db()  : array<string|int, string>
Prepares the given data for insertion into the database.
prepare_item_for_db()  : array<string, mixed>
Prepares the given item for insertion into the database.
update_db()  : bool
Updates the like or not_like count in the database.

Properties

$db

The database instance for report data.

private object $db

$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) : object|false

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
object|false

Database query result or false on failure.

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_or_update_db()

Inserts or updates the given data into the database.

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

If the data exists in the database, it is updated. Otherwise, it is inserted.

Parameters
$data : array<string, mixed>

The data to insert or update.

Return values
int|WP_Error

The id of the created or updated 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.

private 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_likes()

Migrates AI Tool like data from a set of JSON files to the database.

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

Takes an array of file paths and migrates the data in each file to the database. If the file does not exist, or if the data is not in the correct format, the function skips it and continues to the next file.

Parameters
$files : array<string|int, string>

Array of file paths to migrate.

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

Array of migrated row IDs.

prepare_data_for_db()

Prepares the given data for insertion into the database.

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

Converts the json file to an array, formats the keys from camel case to snake case, prepares the item for the database by setting the created date to the current time if not provided, and then adds the app name to the data.

Parameters
$file : string

The json file to read.

Return values
array<string|int, string>

The prepared data.

prepare_item_for_db()

Prepares the given 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.

Parameters
$item : array<string, mixed>

The item to prepare.

Return values
array<string, mixed>

The prepared item.

update_db()

Updates the like or not_like count in the database.

private update_db(object $db_data, array<string, mixed> $data) : bool
Parameters
$db_data : object

The existing database row data.

$data : array<string, mixed>

The data indicating whether it's a like or not like.

Return values
bool

True if the update is successful, false otherwise.


        
On this page

Search results