Skip to content

Commit

Permalink
Correcting initial chicken and egg config save + correcting site var
Browse files Browse the repository at this point in the history
  • Loading branch information
mapkyca committed Dec 2, 2020
1 parent 1210518 commit 9d05714
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
20 changes: 11 additions & 9 deletions Idno/Core/Idno.php
Expand Up @@ -441,19 +441,21 @@ function &site_details() : ? Site

$domain = $this->config()->host;

$this->site_details = Site::getOne([ 'domain' => $domain ]);

if (empty($this->site_details)) {

$this->site_details = new Site();
$this->site_details->domain = $domain;
$this->site_details->save();
if (!empty($domain) && !empty($this->session())) {

$this->site_details = Site::getOne([ 'domain' => $domain ]);

if (empty($this->site_details)) {
throw new \RuntimeException($this->language()->_('Site entity for "%s" could not be created', [$domain]));

$this->site_details = new Site();
$this->site_details->domain = $domain;
$this->site_details->save();

if (empty($this->site_details)) {
throw new \RuntimeException($this->language()->_('Site entity for "%s" could not be created', [$domain]));
}
}
}

}

return $this->site_details;
Expand Down
2 changes: 1 addition & 1 deletion Idno/Data/Mongo.php
Expand Up @@ -173,7 +173,7 @@ function saveRecord($collection, $array)
if (empty($array['_id'])) {

// Save site
if (empty($array['siteid'])) {
if (empty($array['siteid']) && !empty(Idno::site()->site_details())) {
$array['siteid'] = Idno::site()->site_details()->uuid();
}

Expand Down
6 changes: 2 additions & 4 deletions Idno/Data/MySQL.php
Expand Up @@ -181,7 +181,7 @@ function saveRecord($collection, $array)
if (empty($array['_id'])) {
$array['_id'] = $this->generateID();
}
if (empty($array['siteid'])) {
if (empty($array['siteid']) && !empty(Idno::site()->site_details())) {
$array['siteid'] = Idno::site()->site_details()->uuid();
}
if (empty($array['uuid'])) {
Expand Down Expand Up @@ -249,8 +249,6 @@ function saveRecord($collection, $array)
$search = strtolower($search);
$search = Idno::site()->language()->uncurlQuotes($search);

$site = Idno::site()->site_details()->uuid();

$client = $this->client;
/* @var \PDO $client */

Expand All @@ -263,7 +261,7 @@ function saveRecord($collection, $array)
values
(:uuid, :id, :siteid, :subtype, :owner, :contents, :publish_status, :created)
on duplicate key update `uuid` = :uuid, `entity_subtype` = :subtype, `owner` = :owner, `contents` = :contents, `publish_status` = :publish_status, `created` = :created");
if ($statement->execute(array(':uuid' => $array['uuid'], ':id' => $array['_id'], ':siteid' => $site, ':owner' => $array['owner'], ':subtype' => $array['entity_subtype'], ':contents' => $contents, ':publish_status' => $array['publish_status'], ':created' => $array['created']))) {
if ($statement->execute(array(':uuid' => $array['uuid'], ':id' => $array['_id'], ':siteid' => $array['siteid'], ':owner' => $array['owner'], ':subtype' => $array['entity_subtype'], ':contents' => $contents, ':publish_status' => $array['publish_status'], ':created' => $array['created']))) {

// Update FTS
$statement = $client->prepare("insert into {$collection}_search
Expand Down

0 comments on commit 9d05714

Please sign in to comment.