Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
project_composer
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
project_composer
Commits
bf122afe
Commit
bf122afe
authored
1 year ago
by
Neil Drumm
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3399867
: Provide metadata/changes.json endpoint to track updates
parent
c98b8fb4
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#59689
passed with warnings
1 year ago
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
project_composer.changes.inc
+58
-0
58 additions, 0 deletions
project_composer.changes.inc
project_composer.module
+7
-0
7 additions, 0 deletions
project_composer.module
with
65 additions
and
0 deletions
project_composer.changes.inc
0 → 100644
+
58
−
0
View file @
bf122afe
<?php
/**
* Menu callback, list updates.
*
* Implementation of https://packagist.org/apidoc#track-package-updates.
*/
function
project_composer_changes
(
$release_category
)
{
if
(
$release_category
!==
'current'
)
{
return
MENU_NOT_FOUND
;
}
$time
=
(
int
)
(
microtime
(
TRUE
)
*
10000
);
// Get since parameter.
if
(
isset
(
$_REQUEST
[
'since'
])
&&
ctype_digit
(
$_REQUEST
[
'since'
]))
{
$since
=
(
int
)
$_REQUEST
[
'since'
];
}
else
{
http_response_code
(
400
);
drupal_json_output
([
'error'
=>
t
(
'Invalid or missing "since" query parameter, make sure you store the timestamp at the initial point you started mirroring, then send that to begin receiving changes, e.g. !link for example.'
,
[
'!link'
=>
url
(
variable_get
(
'project_composer_packages_url'
,
'https://packages.drupal.org'
)
.
'/8/metadata/changes.json'
,
[
'query'
=>
[
'since'
=>
$time
],
'absolute'
=>
TRUE
]),
]),
'timestamp'
=>
$time
,
]);
return
;
}
// Make sure time is not too far in the past.
if
(
$time
-
$since
>
24
*
60
*
60
*
10000
)
{
drupal_json_output
([
'actions'
=>
[[
'type'
=>
'resync'
,
'time'
=>
floor
(
$time
/
10000
),
'package'
=>
'*'
,
]],
'timestamp'
=>
$time
,
]);
return
;
}
// Generate output.
$actions
=
[];
$result
=
db_query
(
'SELECT package, updated FROM {project_composer_update_log} WHERE category = :release_category AND updated > :since'
,
[
':release_category'
=>
$release_category
,
':since'
=>
floor
(
$since
/
10000
),
]);
foreach
(
$result
as
$row
)
{
$actions
[]
=
[
'type'
=>
'update'
,
'package'
=>
'drupal/'
.
$row
->
package
,
'time'
=>
$row
->
updated
];
}
drupal_json_output
([
'actions'
=>
$actions
,
'timestamp'
=>
$time
]);
}
This diff is collapsed.
Click to expand it.
project_composer.module
+
7
−
0
View file @
bf122afe
...
...
@@ -41,6 +41,13 @@ function project_composer_menu() {
'type'
=>
MENU_CALLBACK
,
'file'
=>
'project_composer.sa.inc'
,
];
$items
[
'packages/%project_composer_endpoint/changes.json'
]
=
[
'page callback'
=>
'project_composer_changes'
,
'page arguments'
=>
[
1
],
'access arguments'
=>
[
'access content'
],
'type'
=>
MENU_CALLBACK
,
'file'
=>
'project_composer.changes.inc'
,
];
return
$items
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment