forked from ymcatwincities/openy_gated_content
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from anpolimus/master
Fix of bugs + code review fixes
- Loading branch information
Showing
19 changed files
with
122 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
modules/openy_gc_shared_content_server/src/Plugin/migrate_plus/data_parser/VirtualYJson.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace Drupal\openy_gc_shared_content_server\Plugin\migrate_plus\data_parser; | ||
|
||
use Drupal\migrate_plus\Plugin\migrate_plus\data_parser\Json; | ||
|
||
/** | ||
* Obtain JSON data for migration. | ||
* | ||
* @DataParser( | ||
* id = "virtualy_json", | ||
* title = @Translation("Virtual Y JSON") | ||
* ) | ||
*/ | ||
class VirtualYJson extends Json { | ||
|
||
/** | ||
* Retrieves the JSON data and returns it as an array. | ||
* | ||
* @param string $url | ||
* URL of a JSON feed. | ||
* | ||
* @return array | ||
* The selected data to be iterated. | ||
* | ||
* @throws \GuzzleHttp\Exception\RequestException | ||
*/ | ||
protected function getSourceData($url) { | ||
$response = $this->getDataFetcherPlugin()->getResponseContent($url); | ||
|
||
// Convert objects to associative arrays. | ||
$source_data = json_decode($response, TRUE); | ||
|
||
// If json_decode() has returned NULL, it might be that the data isn't | ||
// valid utf8 - see http://php.net/manual/en/function.json-decode.php#86997. | ||
if (is_null($source_data)) { | ||
$utf8response = utf8_encode($response); | ||
$source_data = json_decode($utf8response, TRUE); | ||
} | ||
|
||
// Backwards-compatibility for depth selection. | ||
if (is_int($this->itemSelector)) { | ||
return $this->selectByDepth($source_data); | ||
} | ||
|
||
// Otherwise, we're using xpath-like selectors. | ||
$selectors = explode('/', trim($this->itemSelector, '/')); | ||
foreach ($selectors as $selector) { | ||
if (!empty($selector)) { | ||
if (!empty($source_data[$selector])) { | ||
$source_data = $source_data[$selector]; | ||
} | ||
else { | ||
$source_data = []; | ||
} | ||
} | ||
} | ||
|
||
return $source_data; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters