Skip to content

Instantly share code, notes, and snippets.

@itst
Last active January 7, 2022 13:53
Show Gist options
  • Save itst/7ca28ce6a1edf3aaf95cdfe6ddf1c49d to your computer and use it in GitHub Desktop.
Save itst/7ca28ce6a1edf3aaf95cdfe6ddf1c49d to your computer and use it in GitHub Desktop.
When were Confluence Spaces last modified? Use the Confluence REST API to get all Spaces and the date of the latest content change in each.
<?php
define('BASE', 'https://wiki.domain.com/rest/api/');
define('USERNAME' , 'foo');
define('PASSWORD' , 'bar');
function prepareCall(&$curl, $query) {
curl_setopt($curl, CURLOPT_URL, BASE . $query);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERPWD, USERNAME . ':' . PASSWORD);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
}
function getAllSpaces() {
$ch = curl_init();
prepareCall($ch, 'space?expand=metadata&limit=500');
$result = curl_exec($ch);
return $result;
}
function getSpaceDetails($space){
$ch = curl_init();
prepareCall($ch, 'content/search?cql=space%3D' . $space. '%20and%20type%3Dpage%20order%20by%20lastmodified%20desc&expand=version&limit=1');
$result = curl_exec($ch);
return $result;
}
$spaces = json_decode(getAllSpaces());
echo "space;lastModified;\n";
foreach ($spaces->results as $_space) {
$_spaceDetails = json_decode(getSpaceDetails($_space->key));
$_spaces[$_space->key] = $_spaceDetails->results[0]->version->when;
echo $_space->key . ';' . date("d.m.Y", strtotime($_spaceDetails->results[0]->version->when)) . ";\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment