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
58f89e67
Commit
58f89e67
authored
Mar 25, 2019
by
Andrius Mickus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
couple properties
parent
14d9b453
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
29 deletions
+107
-29
JobsImporter.php
wp-content/plugins/jobs-importer/JobsImporter.php
+35
-24
JsonDataCollector.php
wp-content/plugins/jobs-importer/JsonDataCollector.php
+72
-5
No files found.
wp-content/plugins/jobs-importer/JobsImporter.php
View file @
58f89e67
...
...
@@ -30,6 +30,8 @@ class JobsImporter
'comment_status'
=>
'closed'
];
protected
$primaryTerms
=
[];
public
function
__construct
(
$data
)
{
$this
->
data
=
$data
;
...
...
@@ -74,6 +76,8 @@ class JobsImporter
foreach
(
$this
->
data
as
$ad
)
{
$this
->
primaryTerms
=
[];
// Set language code
$lang
=
$this
->
getAdLang
(
$ad
);
// Set relations mapping
...
...
@@ -94,12 +98,6 @@ class JobsImporter
$relations
);
// if ($ad['properties'][$this->primaryKey] == 14531) {
//
// var_dump($ad);
// var_dump($adData);
// }
// Unique key of post
$primaryKey
=
$adData
[
$this
->
primaryKey
];
...
...
@@ -118,6 +116,7 @@ class JobsImporter
print_r
(
"Error while updating record (
$this->idKey
:
$primaryKey
). Error:
$e->getMessage
()<br>"
);
}
}
else
{
try
{
...
...
@@ -132,6 +131,11 @@ class JobsImporter
print_r
(
"Error while creating record (
$this->primaryKey
:
$primaryKey
). Error:
$e->getMessage
()<br>"
);
}
}
foreach
(
$this
->
primaryTerms
as
$term
=>
$termKey
)
{
update_post_meta
(
$podId
,
"_yoast_wpseo_primary_
{
$term
}
"
,
$termKey
);
}
}
}
...
...
@@ -147,9 +151,23 @@ class JobsImporter
{
$result
=
[];
foreach
(
$terms
as
$termKey
=>
$termData
)
{
$slug
=
$this
->
getSlug
(
$termKey
,
$termData
,
$lang
);
$result
[
$termKey
]
=
$this
->
getTerm
(
$termKey
,
$slug
,
$termData
[
'name'
],
$lang
);
foreach
(
$terms
as
$termKey
=>
$termsData
)
{
foreach
(
$termsData
as
$key
=>
$data
)
{
$primTerm
=
false
;
if
(
isset
(
$data
[
'__primary'
]))
{
$primTerm
=
true
;
unset
(
$data
[
'__primary'
]);
}
$data
[
'slug'
]
=
$this
->
getSlug
(
$termKey
,
$data
,
$lang
);
$term
=
$this
->
getTerm
(
$termKey
,
$data
,
$lang
);
$result
[
$termKey
][]
=
$term
;
if
(
$primTerm
)
{
$this
->
primaryTerms
[
$termKey
]
=
$term
;
}
}
}
return
$result
;
...
...
@@ -195,42 +213,35 @@ class JobsImporter
/**
* Find and return taxonomy id, if not exist, create it
*
* @param string $key Taxonomy key name
* @param string $slug Taxonomy slug0
* @param string $value Taxonomy name
* @param string $key Taxonomy key name
* @param $data
* @param string $lang Taxonomy language code
*
* @return int Taxonomy id
*/
private
function
getTerm
(
$key
,
$
slug
,
$value
,
$lang
)
private
function
getTerm
(
$key
,
$
data
,
$lang
)
{
$term
=
pods
(
$key
,
$
slug
);
$term
=
pods
(
$key
,
$
data
[
'slug'
]
);
if
(
!
$term
->
exists
())
{
try
{
$termId
=
pods
(
$key
)
->
add
([
'name'
=>
$value
,
'slug'
=>
$slug
,
]);
$termId
=
pods
(
$key
)
->
add
(
$data
);
}
catch
(
Exception
$e
)
{
print_r
(
"Error while creating taxonomies (
$key
=>
$
slug
). Error:
$e->getMessage
()<br>"
);
print_r
(
"Error while creating taxonomies (
$key
=>
$
data[slug]
). Error:
$e->getMessage
()<br>"
);
}
}
else
{
try
{
$termId
=
$term
->
save
([
'name'
=>
$value
,
'slug'
=>
$slug
,
]);
$termId
=
$term
->
save
(
$data
);
}
catch
(
Exception
$e
)
{
print_r
(
"Error while updating taxonomies (
$key
=>
$
slug
). Error:
$e->getMessage
()<br>"
);
print_r
(
"Error while updating taxonomies (
$key
=>
$
data[slug]
). Error:
$e->getMessage
()<br>"
);
}
}
...
...
wp-content/plugins/jobs-importer/JsonDataCollector.php
View file @
58f89e67
...
...
@@ -23,7 +23,12 @@ class JsonDataCollector
protected
$terms
=
[
'city'
=>
[
'slug'
=>
'miestas_id'
,
'name'
=>
'regionas'
'name'
=>
'regionas'
,
'__primary'
=>
true
,
'additionalCities'
=>
[
'slug'
=>
'city_id'
,
'name'
=>
'city'
,
]
],
'field'
=>
[
'slug'
=>
'kategorija'
,
...
...
@@ -46,7 +51,17 @@ class JsonDataCollector
'title'
=>
'padalinys_name'
,
'slug'
=>
'padalinys'
],
];
protected
$collections
=
[
'city'
=>
[
'name'
=>
'additionalCities'
,
'map'
=>
[
'slug'
=>
'city_id'
,
'name'
=>
'city'
,
],
'append'
=>
'terms:city'
]
];
// Language map
...
...
@@ -124,6 +139,7 @@ class JsonDataCollector
$item
[
'posts'
]
=
$this
->
getPosts
(
$ad
);
$item
[
'relations'
]
=
$this
->
relationsMap
;
// foreach ($this->dataMap as $mapKey => $dataKey) {
// $dataValue = $ad->{$dataKey};
// $itemValue = $this->getValue($dataValue);
...
...
@@ -167,10 +183,18 @@ class JsonDataCollector
$result
=
[];
foreach
(
$this
->
terms
as
$termKey
=>
$termProperties
)
{
foreach
(
$termProperties
as
$propertyKey
=>
$propertyValue
)
{
if
(
isset
(
$ad
->
{
$propertyValue
}))
{
$dataValue
=
$ad
->
{
$propertyValue
};
$result
[
$termKey
][
$propertyKey
]
=
$this
->
getValue
(
$dataValue
);
$result
[
$termKey
][]
=
$this
->
getEntity
(
$ad
,
$termProperties
);
$appends
=
array_filter
(
$termProperties
,
function
(
$item
)
{
return
is_array
(
$item
);
});
foreach
(
$appends
as
$propertyKey
=>
$propertyValues
)
{
if
(
isset
(
$ad
->
{
$propertyKey
}))
{
foreach
(
$ad
->
{
$propertyKey
}
as
$data
)
{
$result
[
$termKey
][]
=
$this
->
getEntity
(
$data
,
$propertyValues
);
}
}
}
}
...
...
@@ -178,6 +202,26 @@ class JsonDataCollector
return
$result
;
}
private
function
getEntity
(
$ad
,
$propertyMap
)
{
$entity
=
[];
foreach
(
$propertyMap
as
$propertyKey
=>
$propertyValue
)
{
if
(
!
is_array
(
$propertyValue
))
{
if
(
preg_match
(
'/^\_\_/'
,
$propertyKey
))
{
$entity
[
$propertyKey
]
=
$propertyValue
;
}
elseif
(
isset
(
$ad
->
{
$propertyValue
}))
{
$dataValue
=
$ad
->
{
$propertyValue
};
$entity
[
$propertyKey
]
=
$this
->
getValue
(
$dataValue
);
}
}
}
return
$entity
;
}
private
function
getPosts
(
$ad
)
{
$result
=
[];
...
...
@@ -194,6 +238,29 @@ class JsonDataCollector
return
$result
;
}
private
function
getCollection
(
$ad
,
$collectionMap
)
{
$result
=
[];
foreach
(
$this
->
collections
as
$collection
)
{
if
(
isset
(
$ad
->
{
$collection
[
'name'
]}))
{
$data
=
$ad
->
{
$collection
[
'name'
]};
}
$entity
=
[];
foreach
(
$collection
[
'map'
]
as
$propertyKey
=>
$propertyValue
)
{
if
(
preg_match
(
'/^\_\_/'
,
$propertyKey
))
{
$entity
[
$propertyKey
]
=
$propertyValue
;
}
elseif
(
isset
(
$data
[
$propertyValue
]))
{
$dataValue
=
$data
[
$propertyValue
];
$entity
[
$propertyKey
]
=
$this
->
getValue
(
$dataValue
);
}
}
}
}
private
function
getValue
(
$value
)
{
return
(
is_array
(
$value
))
?
$value
:
html_entity_decode
(
$value
);
...
...
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