Skip to content

Commit

Permalink
Merge pull request #480 from jjrom/develop
Browse files Browse the repository at this point in the history
Add "All items" title to rel="items" link
  • Loading branch information
jjrom authored Dec 17, 2024
2 parents 5021e72 + c95133e commit 290dcda
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 3 deletions.
46 changes: 46 additions & 0 deletions admin_scripts/migrate_to_9.5.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/command/with-contenv php

<?php

require_once("/app/resto/core/RestoConstants.php");
require_once("/app/resto/core/RestoDatabaseDriver.php");
require_once("/app/resto/core/utils/RestoLogUtil.php");
require_once("/app/resto/core/dbfunctions/UsersFunctions.php");

/*
* Read configuration from file...
*/
$configFile = '/etc/resto/config.php';
if ( !file_exists($configFile)) {
exit(1);
}
$config = include($configFile);
$dbDriver = new RestoDatabaseDriver($config['database'] ?? null);
$queries = [];
try {

$dbDriver->query('BEGIN');

/* User name is now UNIQUE and called username */
$dbDriver->query('UPDATE ' . $dbDriver->targetSchema . '.user SET name = lower(name)');
$dbDriver->query('WITH tmp AS (SELECT name as n FROM ' . $dbDriver->targetSchema . '.user GROUP BY name HAVING count(name) > 1) UPDATE ' . $dbDriver->targetSchema . '.user SET name = tmp.n || (floor(random() * 1000 + 1)::int)::TEXT FROM tmp WHERE name = tmp.n');
$dbDriver->query('UPDATE ' . $dbDriver->targetSchema . '.user SET name = \'anonymous\' || (floor(random() * 1000 + 1)::int)::TEXT WHERE name IS NULL');
$dbDriver->query('ALTER TABLE ' . $dbDriver->commonSchema . '.user RENAME name TO username');
$dbDriver->query('ALTER TABLE ' . $dbDriver->commonSchema . '.user ADD UNIQUE (username)');
$dbDriver->query('ALTER TABLE ' . $dbDriver->commonSchema . '.user ALTER COLUMN settings SET DEFAULT \'{"notifyOnAddFeature":true,"notifyOnNewFollower":true,"notifyOnLikeFeature":true,"notifyOnAddComment":true,"showBio":true,"showIdentity":true,"showTopics":true,"showEmail":false,"profileNeedReview":true}\'');

// Create private group per user
$dbDriver->query('DROP INDEX IF EXISTS ' . $dbDriver->commonSchema . '.idx_uname_group');
$dbDriver->query('WITH tmp AS (SELECT id, username FROM ' . $dbDriver->commonSchema . '.user) INSERT INTO ' . $dbDriver->commonSchema . '.group (name, description, owner, private) SELECT username || \'_private\', \'Private group for user \' || username, id, 1 FROM tmp WHERE username <> \'admin\'');

$dbDriver->query('WITH tmp AS (SELECT id, owner FROM ' . $dbDriver->commonSchema . '.group WHERE private = 1) INSERT INTO ' . $dbDriver->commonSchema . '.group_member (groupid, userid, created) SELECT tmp.id, tmp.owner, now() FROM tmp');

$dbDriver->query('COMMIT');

} catch(Exception $e){
$dbDriver->query('ROLLBACK');
RestoLogUtil::httpError(500, $e->getMessage());
}
echo "Looks good\n";


1 change: 1 addition & 0 deletions app/resto/core/RestoCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ public function toArray()
),
array(
'rel' => 'items',
'title' => 'All items',
'type' => RestoUtil::$contentTypes['geojson'],
'href' => $this->context->core['baseUrl'] . RestoUtil::replaceInTemplate(RestoRouter::ROUTE_TO_FEATURES, array('collectionId' => $this->id))
),
Expand Down
2 changes: 1 addition & 1 deletion app/resto/core/RestoCollections.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function toArray()
),
array(
'rel' => 'items',
'title' => 'All collections',
'title' => 'All items',
'type' => RestoUtil::$contentTypes['geojson'],
'href' => $this->context->core['baseUrl'] . RestoRouter::ROUTE_TO_STAC_SEARCH
)
Expand Down
2 changes: 1 addition & 1 deletion app/resto/core/RestoConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RestoConstants
// [IMPORTANT] Starting resto 7.x, default routes are defined in RestoRouter class

// resto version
const VERSION = '9.4.0';
const VERSION = '9.5.0';

/* ============================================================
* NEVER EVER TOUCH THESE VALUES
Expand Down
1 change: 1 addition & 0 deletions app/resto/core/api/STACAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,7 @@ private function getParentAndChilds($catalogId, $params)
if ( $catalogs[0]['rtype'] === 'collection' ) {
$items = array(
'rel' => 'items',
'title' => 'All items',
'type' => RestoUtil::$contentTypes['geojson'],
'href' => $this->context->core['baseUrl'] . '/collections/' . substr($parentAndChilds['parent']['id'], strrpos($parentAndChilds['parent']['id'], '/') + 1) . '/items'
);
Expand Down
8 changes: 7 additions & 1 deletion examples/catalogs/dummyCatalogChild2.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@
"title": "Dummy Catalog child 2",
"description":"I'm a child of dummyCatalog",
"stac_version":"1.0.0",
"links":[]
"links":[
{
"rel":"item",
"href":"http://127.0.0.1:5252/collections/JohnDoeCollection/items/e3b2cf46-6f4f-58cc-95e9-8686efc89f58",
"title":"Catalog can also have item"
}
]
}
16 changes: 16 additions & 0 deletions examples/catalogs/dummyCatalogWithChilds_update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id": "dummyCatalogWithChilds",
"title": "Dummy Catalog with childs",
"type": "Catalog",
"description":"This catalog has no childs - they will be added later on",
"stac_version":"1.0.0",
"links":[
{
"rel": "child",
"type": "application/json",
"href": "http://127.0.0.1:5252/catalogs/dummyCatalogWithChilds/dummyCatalogChild1",
"title": "Dummy Catalog child 1",
"description": "I'm a child of dummyCatalog"
}
]
}

0 comments on commit 290dcda

Please sign in to comment.