Commit 0110623c authored by Simonas's avatar Simonas

Merge branch 'dev' of git.biuro.lt:biuro/dev.biuro into dev

parents d8cb3c33 4f3c01ad
......@@ -94,6 +94,12 @@ class JobsImporter
$relations
);
// if ($ad['properties'][$this->primaryKey] == 14531) {
//
// var_dump($ad);
// var_dump($adData);
// }
// Unique key of post
$primaryKey = $adData[$this->primaryKey];
......@@ -104,6 +110,8 @@ class JobsImporter
try {
$podId = $pod->save($adData);
// Set post language
$this->setPostLang($podId, $ad['lang']);
print_r("Old record ($this->primaryKey: $primaryKey) has been updated. <br>");
} catch (Exception $e) {
......@@ -115,24 +123,15 @@ class JobsImporter
try {
$podId = $this->pods->add($adData);
// Set post language
$this->setPostLang($podId, $ad['lang']);
$this->getPod($primaryKey)->save($adData); // Save related data, cause didn't saved on creation
print_r("New record ($this->primaryKey: $primaryKey) has been created. <br>");
} catch (Exception $e) {
print_r("Error while creating record ($this->primaryKey: $primaryKey). Error: $e->getMessage()<br>");
}
}
if (isset($podId)) {
// Set post language
$this->setPostLang($podId, $ad['lang']);
// if (isset($custom_uri)) {
// $permalink_manager_uris[$podId] = $custom_uri;
// update_option('permalink-manager-uris', $permalink_manager_uris);
// }
}
}
}
......
......@@ -38,10 +38,14 @@ function importer_admin_menu()
*/
function do_import()
{
// Set environment type
// $env = 'prod';
$env = 'dev';
$env = 'prod';
//Set dev env. only on dev subdomain
$subDomain = strstr($_SERVER['SERVER_NAME'], '.biuro.lt', true);
if ($subDomain == 'dev') {
$env = 'dev';
}
// Set data source path by environment type
if ($env === 'dev') {
......@@ -51,30 +55,64 @@ function do_import()
$inputFile = "http://export.biuro.lt/wp_biuro.php";
}
print_r("<div style='background: lightgrey;'>
<small style='float: right;'>Working in <strong>$env</strong> mode</small>
<div style='clear: both;'></div>
</div>");
echo "<pre>";
print_r('<h4>Biuro Jobs importer</h4>');
print_r("Running in <strong>$env</strong> environment.");
echo "<br><br>";
print_r("Data source: $inputFile<br>");
// if (pll_current_language() != '')
// {
// print_r("<h5 class='warning'>Polylang must be set in 'All languages' mode.</h5>");
// pll_the_languages( array( 'dropdown' => 1 ) );
// exit();
// }
print_r("Data source: $inputFile<br><br>");
// JSON reader
$ads = (new JsonDataCollector($inputFile))->getData();
// var_dump($ads);
// exit();
print_r("Found " . count($ads) . " ads from Biuro.<br>");
if (count($ads) > 0) {
print_r("importing....<br><br>");
if (empty($_POST)) {
// Form for import start, set polylang to 'All lang.' for action
print_r("<form method='post' action='" . current_location() . "&lang=all'>");
print_r("<div style='margin-top: 10px;'><button name='import' value='true'>Import</button></div>");
print_r("</form>");
}
// Posts (via Pods framework) creator
(new JobsImporter($ads))->import();
// for cron, needs add to url ...&lang=all&proceed=1
if (isset($_POST['import']) || isset($_GET['proceed'])) {
print_r("importing....<br><br>");
// Posts (via Pods framework) creator
(new JobsImporter($ads))->import();
}
} else {
print_r("<br>There is nothing more to do.");
}
echo "</pre>";
}
function current_location()
{
if (isset($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$protocol = 'https://';
} else {
$protocol = 'http://';
}
return $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment