Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dev.biuro
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Biuro
dev.biuro
Commits
b3aeff03
Commit
b3aeff03
authored
Sep 11, 2019
by
Simonas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
import endpoint added
parent
7af34033
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
22 deletions
+80
-22
server-shared.conf
nginx/conf.d/server-shared.conf
+6
-0
JobsImporter.php
wp-content/plugins/jobs-importer/JobsImporter.php
+56
-22
functions.php
wp-content/themes/biuro/functions.php
+18
-0
No files found.
nginx/conf.d/server-shared.conf
View file @
b3aeff03
...
...
@@ -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
;
...
...
wp-content/plugins/jobs-importer/JobsImporter.php
View file @
b3aeff03
...
...
@@ -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,12 +128,15 @@ class JobsImporter
$podId
=
$pod
->
save
(
$adData
);
// Set post language
$this
->
setPostLang
(
$podId
,
$ad
[
'lang'
]);
print_r
(
"Job ID: <b>
$podId
</b> <br>"
);
print_r
(
"Old record (
$this->primaryKey
:
$primaryKey
) has been updated. <br>"
);
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
)
{
print_r
(
"Error while updating record (
$this->idKey
:
$primaryKey
). Error:
$e->getMessage
()<br>"
);
if
(
$this
->
log
)
{
print_r
(
"Error while updating record (
$this->idKey
:
$primaryKey
). Error:
$e->getMessage
()<br>"
);
}
}
}
else
{
...
...
@@ -126,10 +147,13 @@ class JobsImporter
// 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>"
);
if
(
$this
->
log
)
{
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
(
$this
->
log
)
{
print_r
(
"Error while creating record (
$this->primaryKey
:
$primaryKey
). Error:
$e->getMessage
()<br>"
);
}
}
}
...
...
@@ -255,8 +279,9 @@ class JobsImporter
$termId
=
pods
(
$key
)
->
add
(
$data
);
}
catch
(
Exception
$e
)
{
print_r
(
"Error while creating taxonomies (
$key
=>
$data[slug]
). Error:
$e->getMessage
()<br>"
);
if
(
$this
->
log
)
{
print_r
(
"Error while creating taxonomies (
$key
=>
$data[slug]
). Error:
$e->getMessage
()<br>"
);
}
}
}
else
{
...
...
@@ -265,8 +290,9 @@ class JobsImporter
$termId
=
$term
->
save
(
$data
);
}
catch
(
Exception
$e
)
{
print_r
(
"Error while updating taxonomies (
$key
=>
$data[slug]
). Error:
$e->getMessage
()<br>"
);
if
(
$this
->
log
)
{
print_r
(
"Error while updating taxonomies (
$key
=>
$data[slug]
). Error:
$e->getMessage
()<br>"
);
}
}
}
...
...
@@ -308,8 +334,9 @@ class JobsImporter
);
}
catch
(
Exception
$e
)
{
print_r
(
"Error while creating custom post (
$key
=>
$slug
). Error:
$e->getMessage
()<br>"
);
if
(
$this
->
log
)
{
print_r
(
"Error while creating custom post (
$key
=>
$slug
). Error:
$e->getMessage
()<br>"
);
}
}
}
else
{
...
...
@@ -324,8 +351,9 @@ class JobsImporter
);
}
catch
(
Exception
$e
)
{
print_r
(
"Error while updating custom post (
$key
=>
$slug
). Error:
$e->getMessage
()<br>"
);
if
(
$this
->
log
)
{
print_r
(
"Error while updating custom post (
$key
=>
$slug
). Error:
$e->getMessage
()<br>"
);
}
}
}
...
...
@@ -351,11 +379,14 @@ class JobsImporter
try
{
PLL
()
->
model
->
post
->
set_language
(
$postId
,
$lang
);
print_r
(
"Set language code '
$lang
' for custom post (id:
$postId
). <br>"
);
if
(
$this
->
log
)
{
print_r
(
"Set language code '
$lang
' for custom post (id:
$postId
). <br>"
);
}
}
catch
(
Exception
$e
)
{
print_r
(
"Error while setting language code for custom post (id:
$postId
), error:
$e->getMessage
().<br>"
);
if
(
$this
->
log
)
{
print_r
(
"Error while setting language code for custom post (id:
$postId
), error:
$e->getMessage
().<br>"
);
}
}
}
...
...
@@ -370,11 +401,14 @@ class JobsImporter
try
{
PLL
()
->
model
->
term
->
set_language
(
$termId
,
$lang
);
print_r
(
"Set language code '
$lang
' for taxonomy (id:
$termId
). <br>"
);
if
(
$this
->
log
)
{
print_r
(
"Set language code '
$lang
' for taxonomy (id:
$termId
). <br>"
);
}
}
catch
(
Exception
$e
)
{
print_r
(
"Error while setting language code for taxonomy (id:
$termId
), error:
$e->getMessage
().<br>"
);
if
(
$this
->
log
)
{
print_r
(
"Error while setting language code for taxonomy (id:
$termId
), error:
$e->getMessage
().<br>"
);
}
}
}
...
...
wp-content/themes/biuro/functions.php
View file @
b3aeff03
...
...
@@ -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 );
// }
// ]
// ]
));
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment