Skip to content

Commit

Permalink
Merge hotfix-3-0-0-rc-10 (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketMan authored Dec 11, 2024
1 parent 8c4a6ca commit fa2f433
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 24 deletions.
3 changes: 2 additions & 1 deletion api/Albums.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public static function fromRecord($rec, $wantTracks = true) {
$res = new JsonResource("album", $rec["tag"]);
$res->links()->set(new Link("self", Engine::getBaseUrl()."album/".$rec["tag"]));
foreach(self::FIELDS as $field) {
if(!array_key_exists($field, $rec))
$tfield = $field == "coll" ? "iscoll" : $field;
if(!array_key_exists($tfield, $rec))
continue;

switch($field) {
Expand Down
10 changes: 5 additions & 5 deletions api/OffsetPaginationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Enm\JsonApi\Exception\NotAllowedException;
use Enm\JsonApi\Model\Document\Document;
use Enm\JsonApi\Model\Request\RequestInterface;
use Enm\JsonApi\Model\Resource\JsonResource;
use Enm\JsonApi\Model\Resource\Link\Link;
use Enm\JsonApi\Model\Resource\Relationship\Relationship;
use Enm\JsonApi\Model\Resource\ResourceCollection;
Expand Down Expand Up @@ -143,11 +144,10 @@ protected function marshallReviews(array $records, $flags) {
$relation->links()->set(new Link("related", Engine::getBaseUrl()."album/{$record["tag"]}/reviews"));
$resource->relationships()->set($relation);
if($flags & Albums::LINKS_REVIEWS_WITH_BODY) {
$reviews = Engine::api(IReview::class)->getReviews($record["id"], 1, "", Engine::session()->isAuth("u"), 1);
$record["airname"] = $reviews[0]["airname"] ?? $reviews[0]["realname"];
$record["review"] = $reviews[0]["review"];
}
$res = Reviews::fromRecord($record);
$review = Engine::api(IReview::class)->getReviews($record["id"], 1, "", Engine::session()->isAuth("u"), 1)[0];
$res = Reviews::fromRecord($review);
} else
$res = new JsonResource("review", $record["id"]);
$res->metaInformation()->set("date", $record["reviewed"]);
$relations->set($res);

Expand Down
5 changes: 1 addition & 4 deletions api/Reviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,9 @@ public static function fromRecord($rec) {
$res = new JsonResource("review", $rec["id"]);
$res->links()->set(new Link("self", Engine::getBaseUrl()."review/".$rec["id"]));
foreach(self::FIELDS as $field) {
if(!array_key_exists($field, $rec))
continue;

switch($field) {
case "date":
$value = substr($rec["reviewed"], 0, 10);
$value = substr($rec["reviewed"] ?? $rec["created"], 0, 10);
break;
case "airname":
$value = $rec["airname"] ?? $rec["realname"];
Expand Down
19 changes: 10 additions & 9 deletions controllers/SSOCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zookeeper Online
*
* @author Jim Mason <[email protected]>
* @copyright Copyright (C) 1997-2023 Jim Mason <[email protected]>
* @copyright Copyright (C) 1997-2024 Jim Mason <[email protected]>
* @link https://zookeeper.ibinx.com/
* @license GPL-3.0
*
Expand Down Expand Up @@ -141,14 +141,15 @@ public static function setupSSOByAccount($account) {
}
return $retval;
}

public static function setupSSOByName($account, $name) {
$retval = false;
$row = Engine::api(IUser::class)->getUserByFullname($name);
if($row) {
Engine::api(IUser::class)->assignAccount($row["name"], $account);
$retval = self::setupSSOByAccount($account);
}
return $retval;
$api = Engine::api(IUser::class);
$row = $api->getUserByFullname($name);
if($row)
$api->assignAccount($row["name"], $account);
else
$api->createNewAccount($name, $account);

return self::setupSSOByAccount($account);
}
}
4 changes: 2 additions & 2 deletions engine/impl/UserImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zookeeper Online
*
* @author Jim Mason <[email protected]>
* @copyright Copyright (C) 1997-2022 Jim Mason <[email protected]>
* @copyright Copyright (C) 1997-2024 Jim Mason <[email protected]>
* @link https://zookeeper.ibinx.com/
* @license GPL-3.0
*
Expand Down Expand Up @@ -50,7 +50,7 @@ public function getUserByAccount($account) {
}

public function getUserByFullname($fullname) {
$query = "SELECT * FROM users WHERE realname = ?";
$query = "SELECT * FROM users WHERE realname = ? AND ssoaccount IS NULL";
$stmt = $this->prepare($query);
$stmt->bindValue(1, $fullname);
return $stmt->executeAndFetch();
Expand Down
30 changes: 27 additions & 3 deletions ui/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,35 @@ private function prefillTracks() {
!preg_match('|/spacer.gif$|', $result->cover_image) ?
$result->cover_image : null;
$infoUrl = self::DISCOGS_BASE . $result->uri;

$response = $discogs->get($result->resource_url);
$page = $response->getBody()->getContents();
$json = json_decode($page);
$seq = 0;
$tracks = [];
$addUrls = $this->getUrlAutofill();
foreach($json->tracklist as $track) {
if($track->type_ == "index") {
$title = !empty($track->title) &&
preg_match('/^(.+?)(?:\s\(.+\))?$/', $track->title, $matches) ?
"{$matches[1]}: " : '';

foreach($track->sub_tracks as $track) {
$entry = [];
$entry["seq"] = ++$seq;
$entry["oseq"] = trim($track->position);
$entry["time"] = trim($track->duration);
$entry["title"] = mb_substr($title . trim($track->title), 0, PlaylistEntry::MAX_FIELD_LENGTH);

// strip optional numeric suffix from artist name
if(!empty($track->artists) &&
preg_match('/^(.+?)(?:\s\(\d+\))?$/', $track->artists[0]->name, $matches))
$entry["artist"] = mb_substr(trim($matches[1]), 0, PlaylistEntry::MAX_FIELD_LENGTH);

$tracks[] = $entry;
}
continue;
}

if($track->type_ != "track")
continue;

Expand All @@ -313,8 +334,11 @@ private function prefillTracks() {
$entry["oseq"] = trim($track->position);
$entry["time"] = trim($track->duration);
$entry["title"] = mb_substr(trim($track->title), 0, PlaylistEntry::MAX_FIELD_LENGTH);
if($track->artists)
$entry["artist"] = mb_substr(trim($track->artists[0]->name), 0, PlaylistEntry::MAX_FIELD_LENGTH);
// strip optional numeric suffix from artist name
if(!empty($track->artists) &&
preg_match('/^(.+?)(?:\s\(\d+\))?$/', $track->artists[0]->name, $matches))
$entry["artist"] = mb_substr(trim($matches[1]), 0, PlaylistEntry::MAX_FIELD_LENGTH);

if($addUrls && $json->videos) {
foreach($json->videos as $key => $video) {
if(mb_stripos($video->title, $entry['title']) !== false) {
Expand Down

0 comments on commit fa2f433

Please sign in to comment.