SLP_Power_Locations_Import
extends SLPlus_BaseClass_Object
in package
CSV Import handler for locations.
Table of Contents
Constants
- csv_import_hook = 'cron_csv_import'
- hook = 'slp_import_locations'
Properties
- $addon : SLPPower
- $addon : mixed
- $adle_setting : bool
- $attachment_id : int
- $data : array<string|int, string>
- $fieldnames : array<string|int, string>
- $file_meta : mixed
- $filehandle : mixed
- $filehandle : mixed
- $load_data : bool
- $maxcols : int
- $messages : SLP_Message_Manager
- $messages : mixed
- $mode_for_current_record : string
- $output : string
- $output : mixed
- $processing_report : array<string|int, string>
- $processing_report : mixed
- $reported_too_many_fields : bool
- $skip_geocoding : bool
- $slplus : SLPlus
- $update_codes : mixed
- $uses_slplus : bool
- $slplus : mixed
- $uses_slplus : mixed
- $adle_setting : mixed
- $attachment_id : mixed
- $base_fieldnames : mixed
- $csv_clear_messages_on_import : mixed
- $data : mixed
- $default_mode : mixed
- $fieldnames : mixed
- $load_data : mixed
- $maxcols : mixed
- $mode_for_current_record : mixed
- $reported_too_many_fields : mixed
- $skip_geocoding : mixed
Methods
- __construct() : mixed
- __get() : SLPlus_BaseClass_Object
- __isset() : bool
- add_sl_to_base_fieldnames() : array<string|int, mixed>
- Add sl_ to any base data fields (id, store, address, address2, etc.) that are in the location data.
- add_upload_meta() : mixed
- Add upload meta.
- get_active_list() : array<string|int, mixed>
- Return a list of active location imports by attachment ID.
- get_instance() : SLPlus_BaseClass_Object
- Return an instance of the object which is also registered to the slplus global less the SLP_ part.
- get_scheduled_list() : array<string|int, mixed>
- Get a list of scheduled (cron/recurring) imports.
- import() : mixed
- Process the locations csv file.
- initialize() : mixed
- Things we do at startup.
- match_identifier_field_on_import() : array<string|int, mixed>
- Look to see if incoming Identifier data is already in the extended data set.
- prepare_for_import() : mixed
- Things we do to prepare for an import.
- process_each_csv_line() : mixed
- Process the lines of the CSV file.
- return_base_fields_only() : bool
- Only use the base table fields.
- set_properties() : mixed
- Set our properties.
- sql_match_identifier() : string
- Add the identifier filter to the SQL where clause.
- start_detached_import() : false|int
- Start a detached import.
- start_remote_file_import() : int|void
- Remote File Importer
- stop_processing() : mixed
- Stop file processing, update meta.
- strip_extra_spaces_from_csv_location_data() : array<string|int, string>
- Strip extra spaces from location data.
- update_category_and_page_id() : mixed
- Attach our category data to the update string.
- filter_SetMessages() : array<string|int, mixed>
- Set the process count output strings the users sees after an upload.
- get_attachment_details() : array<string|int, mixed>
- Get attachment details
- get_remote_file() : mixed
- Get a remote file and store it locally.
- is_valid_csv_file() : bool
- Is this a valid CSV File?
- load_directly_into_mysql() : mixed
- Load basic CSV files directly into MYSQL with LOAD DATA.
- map_fields() : array<string|int, mixed>
- Map field name "aliases" to location data fields for import.
- move_csv_to_slpdir() : string
- Move the CSV File to a local directory.
- ok_to_process_file() : bool
- Override this to add special processing that skips the data processing of the file.
- open_csv_file() : bool
- Open the CSV File and set the filehandle.
- open_file_and_start_importing() : mixed
- Load the CSV file and start importing it into memory.
- process_File() : mixed
- Process a CSV File.
- report_malformed_csv_record() : mixed
- Report a malformed CSV record.
- respawn() : false|int
- Respawn a single me, if I am not already in the spawning pool.
- set_field_names() : mixed
- Set the field names array for the fields being processed.
- set_FileMeta() : mixed
- Set file meta for the import.
- set_options_from_meta() : mixed
- Set options for CSV Import from meta
- set_uploads_meta() : mixed
- Set uploads meta for upload directory parsing.
- strip_utf8_control_chars() : string
- Strip UTF-8 control characters
- update_position_meta() : mixed
- Update the position meta data.
Constants
csv_import_hook
public
mixed
csv_import_hook
= 'cron_csv_import'
hook
public
mixed
hook
= 'slp_import_locations'
Properties
$addon
public
SLPPower
$addon
This addon pack.
$addon
public
mixed
$addon
$adle_setting
public
bool
$adle_setting
Autodetect line endings setting.
$attachment_id read-only
public
int
$attachment_id
The ID of the media file being processed.
$data
public
array<string|int, string>
$data
The current CSV data array.
$fieldnames
public
array<string|int, string>
$fieldnames
List of field names being processed.
$file_meta
public
mixed
$file_meta
= \null
$filehandle
public
mixed
$filehandle
The CSV file handle.
$filehandle
public
mixed
$filehandle
$load_data read-only
public
bool
$load_data
$maxcols
public
int
$maxcols
What is the maximum data columns allowed for this CSV file?
$messages
public
SLP_Message_Manager
$messages
The message stack for the current import operation.
$messages
public
mixed
$messages
$mode_for_current_record read-only
public
string
$mode_for_current_record
What mode is the current record in 'add' || 'update' || 'skip' - set by internal processes
$output
public
string
$output
Output format 'html' or 'json'
$output
public
mixed
$output
= 'html'
$processing_report
public
array<string|int, string>
$processing_report
The processing report.
$processing_report
public
mixed
$processing_report
= array()
$reported_too_many_fields read-only
public
bool
$reported_too_many_fields
Did we already report a too many fields problem?
$skip_geocoding read-only
public
bool
$skip_geocoding
Should geocoding be skipped?
$slplus
public
SLPlus
$slplus
$update_codes
public
mixed
$update_codes
= array('added', 'exists', 'not_updated', 'skipped', 'malformed', 'updated')
$uses_slplus
public
bool
$uses_slplus
Set to true (default) if the object needs access to the SLPlus plugin object.
$slplus
protected
mixed
$slplus
$uses_slplus
protected
mixed
$uses_slplus
= \true
$adle_setting
private
mixed
$adle_setting
$attachment_id
private
mixed
$attachment_id
$base_fieldnames
private
mixed
$base_fieldnames
= array('id' => 'sl_id', 'store' => 'sl_store', 'address' => 'sl_address', 'address2' => 'sl_address2', 'city' => 'sl_city', 'state' => 'sl_state', 'zip' => 'sl_zip', 'country' => 'sl_country', 'latitude' => 'sl_latitude', 'longitude' => 'sl_longitude')
$csv_clear_messages_on_import
private
mixed
$csv_clear_messages_on_import
= \true
$data
private
mixed
$data
$default_mode
private
mixed
$default_mode
$fieldnames
private
mixed
$fieldnames
$load_data
private
mixed
$load_data
$maxcols
private
mixed
$maxcols
$mode_for_current_record
private
mixed
$mode_for_current_record
$reported_too_many_fields
private
mixed
$reported_too_many_fields
= \false
$skip_geocoding
private
mixed
$skip_geocoding
= \false
Methods
__construct()
public
__construct([array<string|int, mixed> $options = array() ]) : mixed
Parameters
- $options : array<string|int, mixed> = array()
__get()
public
__get(string $property) : SLPlus_BaseClass_Object
Parameters
- $property : string
Return values
SLPlus_BaseClass_Object__isset()
public
__isset(string $property) : bool
Parameters
- $property : string
Return values
booladd_sl_to_base_fieldnames()
Add sl_ to any base data fields (id, store, address, address2, etc.) that are in the location data.
public
add_sl_to_base_fieldnames(array<string|int, mixed> $location_data) : array<string|int, mixed>
Parameters
- $location_data : array<string|int, mixed>
Return values
array<string|int, mixed> —location data with 'sl_' attached to the keys that are base fields.
add_upload_meta()
Add upload meta.
public
add_upload_meta(array<string|int, mixed>|bool $data, int $attachment_id) : mixed
Parameters
- $data : array<string|int, mixed>|bool
-
Array of meta data for the given attachment, or false if the object does not exist.
- $attachment_id : int
-
Attachment post ID.
get_active_list()
Return a list of active location imports by attachment ID.
public
get_active_list() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>get_instance()
Return an instance of the object which is also registered to the slplus global less the SLP_ part.
public
static get_instance([bool $no_global = false ][, mixed $params = array() ]) : SLPlus_BaseClass_Object
TODO: PHP7.4 and PHP8.0 the static instance variable returns an object matching $class TODO: PHP8.1 the static instance continually returns the FIRST object (SLP_Admin_Helper) every time -- it is like PHP8.1 static instance is bound to base_class-object versus the calling class object
Parameters
- $no_global : bool = false
-
set to true to skip assigning object to SLP global as a property.
- $params : mixed = array()
-
object init params
Return values
SLPlus_BaseClass_Objectget_scheduled_list()
Get a list of scheduled (cron/recurring) imports.
public
get_scheduled_list() : array<string|int, mixed>
Return values
array<string|int, mixed>import()
Process the locations csv file.
public
import(int $attachment_id) : mixed
Parameters
- $attachment_id : int
Tags
initialize()
Things we do at startup.
public
initialize() : mixed
Tags
match_identifier_field_on_import()
Look to see if incoming Identifier data is already in the extended data set.
public
match_identifier_field_on_import(array<string|int, mixed> $location_data) : array<string|int, mixed>
Parameters
- $location_data : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —$location_data
prepare_for_import()
Things we do to prepare for an import.
public
prepare_for_import() : mixed
process_each_csv_line()
Process the lines of the CSV file.
public
process_each_csv_line() : mixed
Tags
return_base_fields_only()
Only use the base table fields.
public
return_base_fields_only( $var) : bool
Parameters
Tags
Return values
boolset_properties()
Set our properties.
public
set_properties([array<string|int, mixed> $options = array() ]) : mixed
Parameters
- $options : array<string|int, mixed> = array()
sql_match_identifier()
Add the identifier filter to the SQL where clause.
public
sql_match_identifier(string $sql_slug) : string
Parameters
- $sql_slug : string
-
The SQL command slug
Return values
string —The SQL string snippet
start_detached_import()
Start a detached import.
public
start_detached_import(int|object $attachment) : false|int
Parameters
- $attachment : int|object
-
Attachment ID or object.
Return values
false|int —int of the time import will run if ok , false if not
start_remote_file_import()
Remote File Importer
public
start_remote_file_import( $params) : int|void
Parameters
Return values
int|voidstop_processing()
Stop file processing, update meta.
public
stop_processing(mixed $args[, string $hook = self::hook ]) : mixed
Parameters
- $args : mixed
- $hook : string = self::hook
strip_extra_spaces_from_csv_location_data()
Strip extra spaces from location data.
public
strip_extra_spaces_from_csv_location_data( $location_data) : array<string|int, string>
Parameters
Return values
array<string|int, string> —$location_data
update_category_and_page_id()
Attach our category data to the update string.
public
update_category_and_page_id() : mixed
Put it in the sl_option_value field as a serialized string.
Assumes currentLocation is set.
filter_SetMessages()
Set the process count output strings the users sees after an upload.
private
filter_SetMessages() : array<string|int, mixed>
Return values
array<string|int, mixed>get_attachment_details()
Get attachment details
private
get_attachment_details(int $id) : array<string|int, mixed>
Parameters
- $id : int
Return values
array<string|int, mixed>get_remote_file()
Get a remote file and store it locally.
private
get_remote_file(mixed $params) : mixed
Parameters
- $params : mixed
is_valid_csv_file()
Is this a valid CSV File?
private
is_valid_csv_file() : bool
TODO: old-import but should use some of this for new CSV type checking
Called for scheduled imports only.
Return values
boolload_directly_into_mysql()
Load basic CSV files directly into MYSQL with LOAD DATA.
private
load_directly_into_mysql() : mixed
This is MUCH faster than CSV parsing but requires the CSV has no extended data such as categories, etc.
map_fields()
Map field name "aliases" to location data fields for import.
private
map_fields(array<string|int, mixed> $location_data) : array<string|int, mixed>
Parameters
- $location_data : array<string|int, mixed>
Return values
array<string|int, mixed>move_csv_to_slpdir()
Move the CSV File to a local directory.
private
move_csv_to_slpdir() : string
Return values
stringok_to_process_file()
Override this to add special processing that skips the data processing of the file.
private
ok_to_process_file() : bool
Return values
boolopen_csv_file()
Open the CSV File and set the filehandle.
private
open_csv_file(mixed $filename) : bool
Parameters
- $filename : mixed
Return values
boolopen_file_and_start_importing()
Load the CSV file and start importing it into memory.
private
open_file_and_start_importing() : mixed
process_File()
Process a CSV File.
private
process_File() : mixed
report_malformed_csv_record()
Report a malformed CSV record.
private
report_malformed_csv_record(int $field_count) : mixed
Parameters
- $field_count : int
respawn()
Respawn a single me, if I am not already in the spawning pool.
private
respawn(int $id) : false|int
CRON based import.
Parameters
- $id : int
Tags
Return values
false|intset_field_names()
Set the field names array for the fields being processed.
private
set_field_names() : mixed
set_FileMeta()
Set file meta for the import.
private
set_FileMeta() : mixed
Use the standard browser file upload objects $_FILES if set.
If not set check for a remote file URL and use that.
Tags
set_options_from_meta()
Set options for CSV Import from meta
private
set_options_from_meta() : mixed
set_uploads_meta()
Set uploads meta for upload directory parsing.
private
set_uploads_meta() : mixed
strip_utf8_control_chars()
Strip UTF-8 control characters
private
strip_utf8_control_chars(string $string) : string
Parameters
- $string : string
Return values
stringupdate_position_meta()
Update the position meta data.
private
update_position_meta() : mixed