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 ...@@ -94,6 +94,12 @@ class JobsImporter
$relations $relations
); );
// if ($ad['properties'][$this->primaryKey] == 14531) {
//
// var_dump($ad);
// var_dump($adData);
// }
// Unique key of post // Unique key of post
$primaryKey = $adData[$this->primaryKey]; $primaryKey = $adData[$this->primaryKey];
...@@ -104,6 +110,8 @@ class JobsImporter ...@@ -104,6 +110,8 @@ class JobsImporter
try { try {
$podId = $pod->save($adData); $podId = $pod->save($adData);
// Set post language
$this->setPostLang($podId, $ad['lang']);
print_r("Old record ($this->primaryKey: $primaryKey) has been updated. <br>"); print_r("Old record ($this->primaryKey: $primaryKey) has been updated. <br>");
} catch (Exception $e) { } catch (Exception $e) {
...@@ -115,24 +123,15 @@ class JobsImporter ...@@ -115,24 +123,15 @@ class JobsImporter
try { try {
$podId = $this->pods->add($adData); $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>"); print_r("New record ($this->primaryKey: $primaryKey) has been created. <br>");
} catch (Exception $e) { } catch (Exception $e) {
print_r("Error while creating record ($this->primaryKey: $primaryKey). Error: $e->getMessage()<br>"); 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() ...@@ -38,10 +38,14 @@ function importer_admin_menu()
*/ */
function do_import() function do_import()
{ {
// Set environment type // Set environment type
// $env = 'prod'; $env = 'prod';
//Set dev env. only on dev subdomain
$subDomain = strstr($_SERVER['SERVER_NAME'], '.biuro.lt', true);
if ($subDomain == 'dev') {
$env = 'dev'; $env = 'dev';
}
// Set data source path by environment type // Set data source path by environment type
if ($env === 'dev') { if ($env === 'dev') {
...@@ -51,26 +55,47 @@ function do_import() ...@@ -51,26 +55,47 @@ function do_import()
$inputFile = "http://export.biuro.lt/wp_biuro.php"; $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>"; echo "<pre>";
print_r('<h4>Biuro Jobs importer</h4>'); print_r('<h4>Biuro Jobs importer</h4>');
print_r("Running in <strong>$env</strong> environment.");
echo "<br><br>"; // if (pll_current_language() != '')
print_r("Data source: $inputFile<br>"); // {
// 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 // JSON reader
$ads = (new JsonDataCollector($inputFile))->getData(); $ads = (new JsonDataCollector($inputFile))->getData();
// var_dump($ads);
// exit();
print_r("Found " . count($ads) . " ads from Biuro.<br>"); print_r("Found " . count($ads) . " ads from Biuro.<br>");
if (count($ads) > 0) { if (count($ads) > 0) {
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>");
}
// for cron, needs add to url ...&lang=all&proceed=1
if (isset($_POST['import']) || isset($_GET['proceed'])) {
print_r("importing....<br><br>"); print_r("importing....<br><br>");
// Posts (via Pods framework) creator // Posts (via Pods framework) creator
(new JobsImporter($ads))->import(); (new JobsImporter($ads))->import();
}
} else { } else {
print_r("<br>There is nothing more to do."); print_r("<br>There is nothing more to do.");
} }
...@@ -78,3 +103,16 @@ function do_import() ...@@ -78,3 +103,16 @@ function do_import()
echo "</pre>"; 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