Add temporary metadata for download size tracking

main
Jordi Boggiano 3 years ago
parent 96370657b8
commit 3f243d37c3
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -57,6 +57,13 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
protected $eventDispatcher;
/** @var ProcessExecutor */
protected $process;
/**
* @var array<string, int|string>
* @private
* @internal
*/
public static $downloadMetadata = array();
/**
* @private this is only public for php 5.3 support in closures
*
@ -218,6 +225,7 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
$accept = function ($response) use ($cache, $package, $fileName, $self, &$urls) {
$url = reset($urls);
$cacheKey = $url['cacheKey'];
FileDownloader::$downloadMetadata[$package->getName()] = @filesize($fileName) ?: $response->getHeader('Content-Length') ?: '?';
if ($cache && !$cache->isReadOnly()) {
$self->lastCacheWrites[$package->getName()] = $cacheKey;

@ -23,6 +23,7 @@ use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\DependencyResolver\Operation\UninstallOperation;
use Composer\DependencyResolver\Operation\MarkAliasInstalledOperation;
use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation;
use Composer\Downloader\FileDownloader;
use Composer\EventDispatcher\EventDispatcher;
use Composer\Util\Loop;
use Composer\Util\Platform;
@ -65,6 +66,7 @@ class InstallationManager
public function reset()
{
$this->notifiablePackages = array();
FileDownloader::$downloadMetadata = array();
}
/**
@ -662,10 +664,18 @@ class InstallationManager
$postData = array('downloads' => array());
foreach ($packages as $package) {
$postData['downloads'][] = array(
$packageNotification = array(
'name' => $package->getPrettyName(),
'version' => $package->getVersion(),
);
if (strpos($repoUrl, 'packagist.org/') !== false) {
if (isset(FileDownloader::$downloadMetadata[$package->getName()])) {
$packageNotification['downloaded'] = FileDownloader::$downloadMetadata[$package->getName()];
} else {
$packageNotification['downloaded'] = false;
}
}
$postData['downloads'][] = $packageNotification;
}
$opts = array(

Loading…
Cancel
Save