/**
  * Import data from CSV file into database
  */
 public function import()
 {
     $API = new PerchAPI(1.0, 'root_locator');
     $Lang = $API->get('Lang');
     $Template = $API->get('Template');
     $Template->set('locator/address.html', 'locator');
     $Addresses = new RootLocator_Addresses($API);
     $Tasks = new RootLocator_Tasks($API);
     $data = $this->reader->fetchAssoc();
     foreach ($data as $row) {
         $errors = $this->getRowErrors($row);
         $warnings = $this->getRowWarnings($row);
         if ($errors) {
             $this->addError($row, $Lang->get('‘%s’ columns are missing required data', $errors));
             continue;
         }
         if ($warnings) {
             $this->addWarning($row, $Lang->get('‘%s’ columns are recommended to prevent geocoding errors.', $warnings));
         }
         $imported = $Addresses->create(['addressTitle' => $row['addressTitle'], 'addressBuilding' => $row['addressBuilding'], 'addressStreet' => $row['addressStreet'], 'addressTown' => $row['addressTown'], 'addressRegion' => $row['addressRegion'], 'addressPostcode' => $row['addressPostcode'], 'addressCountry' => $row['addressCountry']]);
         $imported->index($Template);
         $Tasks->add('address.geocode', $imported->id());
         $this->addSuccess($row);
     }
 }
Ejemplo n.º 2
0
function root_locator_process_task_queue($last_run_date)
{
    include __DIR__ . '/lib/vendor/autoload.php';
    spl_autoload_register(function ($class_name) {
        if (strpos($class_name, 'RootLocator') === 0) {
            include PERCH_PATH . '/addons/apps/root_locator/lib/' . $class_name . '.class.php';
            return true;
        }
        return false;
    });
    $API = new PerchAPI(1.0, 'root_locator');
    $Tasks = new RootLocator_Tasks($API);
    $result = $Tasks->processQueue(1);
    if ($result === false) {
        return ['status' => 'ERROR', 'message' => 'There was an error processing the task queue'];
    }
    return ['status' => 'OK', 'message' => sprintf('%s tasks processed', $result)];
}
<?php

// Data
$Addresses = new RootLocator_Addresses($API);
$Tasks = new RootLocator_Tasks($API);
$result = false;
// Master template
$Template->set('locator/address.html', 'locator');
// Edit / Create
if (isset($_GET['id']) && $_GET['id'] != '') {
    $addressID = (int) $_GET['id'];
    $Address = $Addresses->find($addressID);
    $details = $Address->to_array();
    $heading1 = 'Addresses / Edit Address';
} else {
    $addressID = false;
    $Address = false;
    $details = [];
    $heading1 = 'Locations / Add Address';
}
// Forms
$Form->handle_empty_block_generation($Template);
$Form->require_field('addressTitle', 'This field is required');
$Form->require_field('addressStreet', 'This field is required');
$Form->require_field('addressPostcode', 'This field is required');
$Form->set_required_fields_from_template($Template, $details);
if ($Form->submitted()) {
    $postvars = ['addressTitle', 'addressBuilding', 'addressStreet', 'addressTown', 'addressRegion', 'addressCountry', 'addressPostcode', 'force'];
    $data = $Form->receive($postvars);
    // Force?
    $force = false;
Ejemplo n.º 4
0
<?php

$Addresses = new RootLocator_Addresses($API);
$Tasks = new RootLocator_Tasks($API);
$Paging->set_per_page(10);
if ($Paging->is_first_page()) {
    // Update permissions
    $UserPrivileges = $API->get('UserPrivileges');
    $UserPrivileges->create_privilege('root_locator', 'Access the locator app');
    $UserPrivileges->create_privilege('root_locator.import', 'Mass import location data');
    // Convert categories
    $sql = 'UPDATE ' . PERCH_DB_PREFIX . 'category_sets 
            SET setTemplate="~root_locator/templates/locator/category_set.html", setCatTemplate="~root_locator/templates/locator/category.html"
            WHERE setTemplate="~/jw_locator/templates/locator/category_set.html"
            AND setCatTemplate="~/jw_locator/templates/locator/category.html"';
    $db->execute($sql);
}
if ($Settings->get('root_locator_update')->val() != '2.0.0') {
    $legacy = $Addresses->getLegacyData($Paging);
    if (PerchUtil::count($legacy)) {
        foreach ($legacy as $row) {
            // Ok, we have an error and it's not a quota issue, so just save as is.
            if (isset($row['errorMessage']) && !empty($row['errorMessage']) && $row['errorMessage'] == 'The address could not be found.') {
                $legacyAddress = $Addresses->create(['addressTitle' => $row['locationTitle'], 'addressBuilding' => $row['locationBuilding'], 'addressStreet' => $row['locationStreet'], 'addressTown' => $row['locationTown'], 'addressRegion' => $row['locationRegion'], 'addressPostcode' => $row['locationPostcode'], 'addressCountry' => $row['locationPostcode'], 'addressDynamicFields' => $row['locationDynamicFields'], 'addressError' => 'no_results']);
                $legacyAddress->index();
                continue;
            }
            // Do we have some existing location data we can just simply shift over?
            if (isset($row['markerLatitude']) && isset($row['markerLongitude'])) {
                $legacyAddress = $Addresses->create(['addressTitle' => $row['locationTitle'], 'addressBuilding' => $row['locationBuilding'], 'addressStreet' => $row['locationStreet'], 'addressTown' => $row['locationTown'], 'addressRegion' => $row['locationRegion'], 'addressPostcode' => $row['locationPostcode'], 'addressCountry' => $row['locationPostcode'], 'addressDynamicFields' => $row['locationDynamicFields'], 'addressLatitude' => $row['markerLatitude'], 'addressLongitude' => $row['markerLongitude']]);
                $legacyAddress->index();