Skip to content

Commit fa7d954

Browse files
committed
Changes Api::getRecursiveMetadata() to always add timestamps
- Timestamps for files are retrieved from the github api - Timestamps for directories are calculated from retrieved files
1 parent 3d5b12e commit fa7d954

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/Api.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,21 +229,43 @@ final public function getMetaData($path)
229229
final public function getRecursiveMetadata($path, $recursive)
230230
{
231231
// If $info['truncated'] is `true`, the number of items in the tree array
232-
// exceeded the github maximum limit. If you need to fetch more items,
232+
// exceeded the github maximum limit. If we need to fetch more items,
233233
// multiple calls will be needed
234234

235235
$info = $this->getGitDataApi()->trees()->show(
236236
$this->settings->getVendor(),
237237
$this->settings->getPackage(),
238238
$this->settings->getReference(),
239-
$recursive
239+
true //@NOTE: To retrieve all needed date the 'recursive' flag should always be 'true'
240240
);
241241

242242
$path = rtrim($path, '/') . '/';
243243

244244
$treeMetadata = $this->extractMetaDataFromTreeInfo($info[self::KEY_TREE], $path, $recursive);
245245

246-
return $this->normalizeTreeMetadata($treeMetadata);
246+
$normalizeTreeMetadata = $this->normalizeTreeMetadata($treeMetadata);
247+
248+
$directoryTimestamp = 0000000000;
249+
250+
array_walk($normalizeTreeMetadata, function (&$entry) use (&$directoryTimestamp) {
251+
if ($this->hasKey($entry, self::KEY_TIMESTAMP) === false
252+
|| $entry[self::KEY_TIMESTAMP] === false
253+
) {
254+
$timestamp = $this->getCreatedTimestamp($entry[self::KEY_PATH])['timestamp'];
255+
256+
$entry[self::KEY_TIMESTAMP] = $timestamp;
257+
258+
if ($timestamp > $directoryTimestamp) {
259+
$directoryTimestamp = $timestamp;
260+
}
261+
}
262+
});
263+
264+
/* @FIXME: It might be wise to use a filter to find the right entry instead of ussing it will always be the first entry in the array. */
265+
266+
$normalizeTreeMetadata[0]['timestamp'] = $directoryTimestamp;
267+
268+
return $normalizeTreeMetadata;
247269
}
248270

249271
/**

0 commit comments

Comments
 (0)