Commit 7ca26824 authored by Simonas's avatar Simonas

Merge branch 'auto-import' into dev

parents 7af34033 3e0973c8
......@@ -31,6 +31,12 @@ location /wp-json/api/v1/recommended {
auth_basic_user_file /etc/nginx/.htpasswd;
}
location /wp-json/api/v1/import-positions {
try_files $uri $uri/ /index.php?$args;
auth_basic "Basic auth";
auth_basic_user_file /etc/nginx/.htpasswd;
}
location = /wp-admin/admin-post.php {
access_log /var/log/nginx/postdata.log postdata;
......
......@@ -127,7 +127,12 @@ class Biuro_Feedbacks extends WP_Widget {
echo '<div class="c-feedbacks--section-inner">';
if ( ${'img' . $i} != "" ) {
echo '<img src="/wp-content/themes/biuro/i/feedbacks/' . ${'img' . $i} . '" class="c-feedbacks--img" width="85px" height="83px" alt="' . ${'name' . $i} . '"/>';
$img = preg_replace('/\.png$/i', '', ${'img' . $i});
echo '<picture class="c-feedbacks--img">';
echo '<source srcset="/wp-content/themes/biuro/i/feedbacks/' . $img . '.webp" type="image/webp">';
echo '<img loading="lazy" src="/wp-content/themes/biuro/i/feedbacks/' . $img . '.png" width="85px" height="83px" alt="Švyturys - Utenos alus" class="' . ${'name' . $i} . '">';
echo '</picture>';
}
if ( ${'feedback' . $i} != "" ) {
......
......@@ -7,10 +7,12 @@
* @package Biuro Jobs importer
* @used-by \jobs-importer\job-importer.php
*/
class JobsImporter
{
private $data;
private $log;
// Biuro record unique key
protected $primaryKey = 'livas-id';
......@@ -32,9 +34,14 @@ class JobsImporter
protected $primaryTerms = [];
public function __construct($data)
public function __construct($data, $log = true)
{
if (!function_exists('is_plugin_active')) {
require_once 'wp-admin/includes/plugin.php';
}
$this->data = $data;
$this->log = $log;
$this->setPods();
}
......@@ -67,6 +74,17 @@ class JobsImporter
return $data;
}
public static function importPositions () {
$env = getEnvironment();
$inputFile = getSource($env);
$ads = (new JsonDataCollector($inputFile))->getData();
(new JobsImporter($ads, false))->import();
exit;
}
/**
* Import posts from provided data: if post with given Id exists, it rewrites
*/
......@@ -110,13 +128,16 @@ class JobsImporter
$podId = $pod->save($adData);
// Set post language
$this->setPostLang($podId, $ad['lang']);
if ($this->log) {
print_r("Job ID: <b>$podId</b> <br>");
print_r("Old record ($this->primaryKey: $primaryKey) has been updated. <br>");
}
} catch (Exception $e) {
if ($this->log) {
print_r("Error while updating record ($this->idKey: $primaryKey). Error: $e->getMessage()<br>");
}
}
} else {
......@@ -126,12 +147,15 @@ class JobsImporter
// Set post language
$this->setPostLang($podId, $ad['lang']);
$this->getPod($primaryKey)->save($adData); // Save related data, cause didn't saved on creation
if ($this->log) {
print_r("New record ($this->primaryKey: $primaryKey) has been created. <br>");
}
} catch (Exception $e) {
if ($this->log) {
print_r("Error while creating record ($this->primaryKey: $primaryKey). Error: $e->getMessage()<br>");
}
}
}
// Set primary properties
if (is_plugin_active('wordpress-seo/wp-seo.php')) {
......@@ -255,9 +279,10 @@ class JobsImporter
$termId = pods($key)->add($data);
} catch (Exception $e) {
if ($this->log) {
print_r("Error while creating taxonomies ($key => $data[slug]). Error: $e->getMessage()<br>");
}
}
} else {
try {
......@@ -265,9 +290,10 @@ class JobsImporter
$termId = $term->save($data);
} catch (Exception $e) {
if ($this->log) {
print_r("Error while updating taxonomies ($key => $data[slug]). Error: $e->getMessage()<br>");
}
}
}
......@@ -308,9 +334,10 @@ class JobsImporter
);
} catch (Exception $e) {
if ($this->log) {
print_r("Error while creating custom post ($key => $slug). Error: $e->getMessage()<br>");
}
}
} else {
try {
......@@ -324,10 +351,11 @@ class JobsImporter
);
} catch (Exception $e) {
if ($this->log) {
print_r("Error while updating custom post ($key => $slug). Error: $e->getMessage()<br>");
}
}
}
if (empty($postId)) {
......@@ -351,13 +379,16 @@ class JobsImporter
try {
PLL()->model->post->set_language($postId, $lang);
if ($this->log) {
print_r("Set language code '$lang' for custom post (id: $postId). <br>");
}
} catch (Exception $e) {
if ($this->log) {
print_r("Error while setting language code for custom post (id: $postId), error: $e->getMessage().<br>");
}
}
}
/**
* Set language param for given taxonomy, using Polylang library
......@@ -370,13 +401,16 @@ class JobsImporter
try {
PLL()->model->term->set_language($termId, $lang);
if ($this->log) {
print_r("Set language code '$lang' for taxonomy (id: $termId). <br>");
}
} catch (Exception $e) {
if ($this->log) {
print_r("Error while setting language code for taxonomy (id: $termId), error: $e->getMessage().<br>");
}
}
}
/**
* Get pod by given id
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -65,7 +65,7 @@
<div class="c-contact-landing-1--img">
<picture>
<source srcset="/wp-content/themes/biuro/i/contact.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/contact.png" alt="" width="328" height="95">
<img loading="lazy" src="/wp-content/themes/biuro/i/contact.png" alt="" width="328" height="95">
</picture>
</div>
</div>
......
......@@ -35,7 +35,7 @@
<div class="c-contact-landing-2--img">
<picture>
<source srcset="/wp-content/themes/biuro/i/contact.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/contact.png" alt="" width="328" height="95">
<img loading="lazy" src="/wp-content/themes/biuro/i/contact.png" alt="" width="328" height="95">
</picture>
</div>
</div>
......
......@@ -148,7 +148,7 @@
<?php
endif;
?>
<script src="/wp-content/themes/biuro/js/main.min.js" async></script>
<script src="/wp-content/themes/biuro/js/main-876e541f.min.js" async></script>
<?php
// global $time_start;
......
......@@ -115,7 +115,7 @@
<div class="c-contact--img">
<picture>
<source srcset="/wp-content/themes/biuro/i/contact.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/contact.png" alt="" width="328" height="95">
<img loading="lazy" src="/wp-content/themes/biuro/i/contact.png" alt="" width="328" height="95">
</picture>
</div>
</div>
......
......@@ -580,6 +580,24 @@ add_action( 'rest_api_init', function () {
]
));
register_rest_route( 'api/v1', '/import-positions', array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'JobsImporter::importPositions',
// 'args' => [
// 'from' => [
// 'validate_callback' => function($param, $request, $key) {
// return is_string( $param );
// }
// ],
// 'by' => [
// 'validate_callback' => function($param, $request, $key) {
// return is_string( $param );
// }
// ]
// ]
));
});
......
......@@ -31,16 +31,19 @@
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-500.woff2" crossorigin="anonymous" >
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-regular.woff2" crossorigin="anonymous" >
<style><?php include 'css/core.min.css'; ?></style>
<style><?php include 'css/core-96be3f17bc.min.css'; ?></style>
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-300.woff2" crossorigin="anonymous" >
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-700.woff2" crossorigin="anonymous" >
<link rel="preload" href="/wp-content/themes/biuro/css/main.min.css" as="style" onload="this.rel='stylesheet'">
<link rel="preload" href="/wp-content/themes/biuro/css/main-1a30808647.min.css" as="style" onload="this.rel='stylesheet'">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link rel="preconnect" href="https://www.gstatic.com">
<noscript>
<link rel="stylesheet" href="/wp-content/themes/biuro/css/main.min.css">
<link rel="stylesheet" href="/wp-content/themes/biuro/css/main-1a30808647.min.css">
</noscript>
<?php wp_head(); ?>
......
......@@ -31,15 +31,18 @@
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-500.woff2" crossorigin="anonymous" >
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-regular.woff2" crossorigin="anonymous" >
<style><?php include 'css/core.min.css'; ?></style>
<style><?php include 'css/core-96be3f17bc.min.css'; ?></style>
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-300.woff2" crossorigin="anonymous" >
<link rel="preload" as="font" type="font/woff2" href="/wp-content/themes/biuro/fonts/roboto-v19-cyrillic_latin_cyrillic-ext_latin-ext-700.woff2" crossorigin="anonymous" >
<link rel="preload" href="/wp-content/themes/biuro/css/main.min.css" as="style" onload="this.rel='stylesheet'">
<link rel="preload" href="/wp-content/themes/biuro/css/main-1a30808647.min.css" as="style" onload="this.rel='stylesheet'">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link rel="preconnect" href="https://www.gstatic.com">
<noscript>
<link rel="stylesheet" href="/wp-content/themes/biuro/css/main.min.css">
<link rel="stylesheet" href="/wp-content/themes/biuro/css/main-1a30808647.min.css">
</noscript>
<?php wp_head(); ?>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -46,7 +46,7 @@
<div class="c-contact-landing-1--img">
<picture>
<source srcset="/wp-content/themes/biuro/i/contact.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/contact.png" alt="" width="328" height="95">
<img loading="lazy" src="/wp-content/themes/biuro/i/contact.png" alt="" width="328" height="95">
</picture>
</div>
</div>
......
......@@ -73,7 +73,7 @@
<div class="c-contact--img">
<picture>
<source srcset="/wp-content/themes/biuro/i/contact.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/contact.png" alt="" width="328" height="95">
<img loading="lazy" src="/wp-content/themes/biuro/i/contact.png" alt="" width="328" height="95">
</picture>
</div>
</div>
......
......@@ -9,59 +9,53 @@
<?php if ($blogID == 1): ?>
<picture>
<source srcset="/wp-content/themes/biuro/i/trust/svyturys.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/trust/svyturys.png" width="109" height="33" alt="Švyturys - Utenos alus" class="c-trust--img-svyturys">
<img loading="lazy" src="/wp-content/themes/biuro/i/trust/svyturys.png" width="109" height="33" alt="Švyturys - Utenos alus" class="c-trust--img-svyturys">
</picture>
<picture>
<source srcset="/wp-content/themes/biuro/i/trust/dpd.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/trust/dpd.png" width="64" height="29" alt="DPD" class="c-trust--img-dpd">
<img loading="lazy" src="/wp-content/themes/biuro/i/trust/dpd.png" width="64" height="29" alt="DPD" class="c-trust--img-dpd">
</picture>
<picture>
<source srcset="/wp-content/themes/biuro/i/trust/pergale.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/trust/pergale.png" width="85" height="19" alt="Vilniaus pergalė" class="c-trust--img-pergale">
<img loading="lazy" src="/wp-content/themes/biuro/i/trust/pergale.png" width="85" height="19" alt="Vilniaus pergalė" class="c-trust--img-pergale">
</picture>
<picture>
<source srcset="/wp-content/themes/biuro/i/trust/maxima.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/trust/maxima.png" width="96" height="22" alt="Maxima" class="c-trust--img-maxima">
<img loading="lazy" src="/wp-content/themes/biuro/i/trust/maxima.png" width="96" height="22" alt="Maxima" class="c-trust--img-maxima">
</picture>
<?php elseif ($blogID == 2): ?>
<picture>
<source srcset="/wp-content/themes/biuro/i/trust/lv/pasts.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/trust/lv/pasts.png" width="122" height="28" alt="Latvijas pasts" class="c-trust--img-pasts">
<img loading="lazy" src="/wp-content/themes/biuro/i/trust/lv/pasts.png" width="122" height="28" alt="Latvijas pasts" class="c-trust--img-pasts">
</picture>
<picture>
<source srcset="/wp-content/themes/biuro/i/trust/lv/dhl.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/trust/lv/dhl.png" width="130" height="18" alt="DHL" class="c-trust--img-dhl">
<img loading="lazy" src="/wp-content/themes/biuro/i/trust/lv/dhl.png" width="130" height="18" alt="DHL" class="c-trust--img-dhl">
</picture>
<picture>
<source srcset="/wp-content/themes/biuro/i/trust/lv/staburadze.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/trust/lv/staburadze.png" width="128" height="38" alt="Staburadze" class="c-trust--img-staburadze">
<img loading="lazy" src="/wp-content/themes/biuro/i/trust/lv/staburadze.png" width="128" height="38" alt="Staburadze" class="c-trust--img-staburadze">
</picture>
<picture>
<source srcset="/wp-content/themes/biuro/i/trust/lv/cido.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/trust/lv/cido.png" width="73" height="47" alt="CIDO" class="c-trust--img-cido">
<img loading="lazy" src="/wp-content/themes/biuro/i/trust/lv/cido.png" width="73" height="47" alt="CIDO" class="c-trust--img-cido">
</picture>
<?php elseif ($blogID == 3): ?>
<picture>
<source srcset="/wp-content/themes/biuro/i/trust/ee/itella.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/trust/ee/itella.png" width="86" height="54" alt="Itella" class="c-trust--img-itella">
<img loading="lazy" src="/wp-content/themes/biuro/i/trust/ee/itella.png" width="86" height="54" alt="Itella" class="c-trust--img-itella">
</picture>
<picture>
<source srcset="/wp-content/themes/biuro/i/trust/ee/saku.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/trust/ee/saku.png" width="80" height="59" alt="Saku" class="c-trust--img-saku">
<img loading="lazy" src="/wp-content/themes/biuro/i/trust/ee/saku.png" width="80" height="59" alt="Saku" class="c-trust--img-saku">
</picture>
<picture>
<source srcset="/wp-content/themes/biuro/i/trust/ee/ipa.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/trust/ee/ipa.png" width="70" height="31" alt="Leibur" class="c-trust--img-ipa">
<img loading="lazy" src="/wp-content/themes/biuro/i/trust/ee/ipa.png" width="70" height="31" alt="Leibur" class="c-trust--img-ipa">
</picture>
<?php /*
<picture>
<source srcset="/wp-content/themes/biuro/i/trust/ee/leibur.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/trust/ee/leibur.png" width="72" height="60" alt="Leibur" class="c-trust--img-leibur">
</picture>
*/ ?>
<picture>
<source srcset="/wp-content/themes/biuro/i/trust/ee/maxima.webp" type="image/webp">
<img src="/wp-content/themes/biuro/i/trust/ee/maxima.png" width="123" height="26" alt="MAXIMA" class="c-trust--img-maxima-ee">
<img loading="lazy" src="/wp-content/themes/biuro/i/trust/ee/maxima.png" width="123" height="26" alt="MAXIMA" class="c-trust--img-maxima-ee">
</picture>
<?php endif; ?>
</div>
......
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