2 namespace TYPO3\CMS\Composer\Installer\Downloader;
27 use Composer\Package\PackageInterface;
28 use Composer\Downloader\ArchiveDownloader;
29 use Composer\Downloader\ChangeReportInterface;
37 class T3xDownloader extends ArchiveDownloader implements ChangeReportInterface {
49 $this->
package = $package;
50 parent::download($package, $path);
57 protected function extract($file, $path) {
59 $fileContentStream = file_get_contents($file);
62 if (substr($path, -1) !== DIRECTORY_SEPARATOR) {
63 $path .= DIRECTORY_SEPARATOR;
78 $path = rtrim($path,
'/') .
'/';
83 $extensionFiles = unserialize($emMetaData[
'_md5_values_when_last_written']);
84 foreach ($extensionFiles as $extensionFileName => $extensionFileHash) {
85 if (substr($extensionFileName, -1) ===
'/') {
88 if (is_file($path . $extensionFileName)) {
89 $localFileContentHash = md5(file_get_contents($path . $extensionFileName));
91 if (substr($localFileContentHash, 0, 4) !== $extensionFileHash) {
92 $messages[] = $extensionFileName .
' - File is modified';
95 $messages[] = $extensionFileName .
' - File is missing';
100 if ($package->getPrettyVersion() !== $emMetaData[
'version']) {
101 $messages[] =
'Local Version is ' . $emMetaData[
'version'] .
' but should be ' . $package->getPrettyVersion();
105 }
catch (\RuntimeException $e) {
106 $messages[] = $e->getMessage();
109 return implode(
"\n", $messages);
117 if (!is_file($path .
'ext_emconf.php')) {
118 throw new \RuntimeException(
'Package is unstable. "ext_emconf.php" is missing', 1439568877);
120 $_EXTKEY = basename($path);
121 include($path .
'ext_emconf.php');
123 if (!is_array(
$EM_CONF[$_EXTKEY])) {
124 throw new \RuntimeException(
'Package is unstable. "ext_emconf.php" is corrupt', 1439569163);
136 $parts = explode(
':', $stream, 3);
137 if ($parts[1] ===
'gzcompress') {
138 if (function_exists(
'gzuncompress')) {
139 $parts[2] = gzuncompress($parts[2]);
141 throw new \RuntimeException(
'Decoding Error: No decompressor available for compressed content. gzcompress()/gzuncompress() functions are not available!', 1359124403);
144 if (md5($parts[2]) === $parts[0]) {
145 $output = unserialize($parts[2]);
146 if (!is_array($output)) {
147 throw new \RuntimeException(
'Error: Content could not be unserialized to an array. Strange (since MD5 hashes match!)', 1359124554);
150 throw new \RuntimeException(
'Error: MD5 mismatch. Maybe the extension file was downloaded and saved as a text file and thereby corrupted!?', 1359124556);
163 return $extensionData[
'FILES'];
173 $directories = array();
174 foreach ($files as $filePath => $file) {
175 preg_match(
'/(.*)\\//', $filePath, $matches);
176 if (count($matches) > 0) {
177 $directories[] = $matches[0];
192 foreach ($directories as $directory) {
204 $currentPath = $directory;
205 if (!@is_dir($currentPath)) {
207 $separatorPosition = strrpos($currentPath, DIRECTORY_SEPARATOR);
208 $currentPath = substr($currentPath, 0, $separatorPosition);
209 }
while (!is_dir($currentPath) && $separatorPosition !== FALSE);
211 $result = @mkdir($directory, 0777, TRUE);
213 throw new \RuntimeException(
'Could not create directory "' . $directory .
'"!', 1170251400);
226 foreach ($files as $file) {
227 if (empty($file[
'name']) || substr($file[
'name'], -1) ===
'/') {
231 $content = $file[
'content'];
233 fwrite($fd, $content);
244 $emConfFileData = array();
245 if (file_exists($path .
'ext_emconf.php')) {
248 $extensionData[
'EM_CONF'] = array_replace_recursive($emConfFileData, $extensionData[
'EM_CONF']);
250 if ($fd = fopen($path .
'ext_emconf.php',
'wb')) {
251 fwrite($fd, $emConfContent);
264 $emConf = $this->
fixEmConf($extensionData[
'EM_CONF']);
265 $emConf[
'_md5_values_when_last_written'] = serialize($this->
extensionMD5array($extensionData[
'FILES']));
266 $uniqueIdentifier = md5($emConf[
'_md5_values_when_last_written']);
267 $emConf = var_export($emConf, TRUE);
270 /***************************************************************
271 * Extension Manager/Repository config file for ext "' . $extensionData[
'extKey'] .
'".
273 * Auto generated | Identifier: ' . $uniqueIdentifier .
'
276 * Only the data in the array - everything else is removed by next
277 * writing. "version" and "dependencies" must not be touched!
278 ***************************************************************/
280 $EM_CONF[$_EXTKEY] = ' . $emConf .
';
283 return str_replace(
' ', chr(9), $code);
296 foreach ($filesArray as $fileName => $fileInfo) {
297 $fileName = ltrim($fileName,
'/');
298 if ($fileName !==
'ext_emconf.php') {
299 $md5Array[$fileName] = substr($fileInfo[
'content_md5'], 0, 4);
314 !isset($emConf[
'constraints']) || !isset($emConf[
'constraints'][
'depends'])
315 || !isset($emConf[
'constraints'][
'conflicts']) || !isset($emConf[
'constraints'][
'suggests'])
317 if (!isset($emConf[
'constraints']) || !isset($emConf[
'constraints'][
'depends'])) {
318 $emConf[
'constraints'][
'depends'] = $this->
stringToDependency($emConf[
'dependencies']);
319 if ((
string)$emConf[
'PHP_version'] !==
'') {
320 $emConf[
'constraints'][
'depends'][
'php'] = $emConf[
'PHP_version'];
322 if ((
string)$emConf[
'TYPO3_version'] !==
'') {
323 $emConf[
'constraints'][
'depends'][
'typo3'] = $emConf[
'TYPO3_version'];
326 if (!isset($emConf[
'constraints']) || !isset($emConf[
'constraints'][
'conflicts'])) {
327 $emConf[
'constraints'][
'conflicts'] = $this->
stringToDependency($emConf[
'conflicts']);
329 if (!isset($emConf[
'constraints']) || !isset($emConf[
'constraints'][
'suggests'])) {
330 $emConf[
'constraints'][
'suggests'] = array();
332 }
elseif (isset($emConf[
'constraints']) && isset($emConf[
'dependencies'])) {
333 $emConf[
'suggests'] = isset($emConf[
'suggests']) ? $emConf[
'suggests'] : array();
335 $emConf[
'conflicts'] = $this->
dependencyToString($emConf[
'constraints'],
'conflicts');
339 unset($emConf[
'dependencies']);
340 unset($emConf[
'conflicts']);
341 unset($emConf[
'suggests']);
342 unset($emConf[
'private']);
343 unset($emConf[
'download_password']);
344 unset($emConf[
'TYPO3_version']);
345 unset($emConf[
'PHP_version']);
346 unset($emConf[
'internal']);
347 unset($emConf[
'module']);
348 unset($emConf[
'loadOrder']);
349 unset($emConf[
'lockType']);
350 unset($emConf[
'shy']);
351 unset($emConf[
'priority']);
352 unset($emConf[
'modify_tables']);
353 unset($emConf[
'CGLcompliance']);
354 unset($emConf[
'CGLcompliance_note']);
371 if (is_array($dependency)) {
372 if (isset($dependency[$type][
'php'])) {
373 unset($dependency[$type][
'php']);
375 if (isset($dependency[$type][
'typo3'])) {
376 unset($dependency[$type][
'typo3']);
378 $dependencyString = count($dependency[$type]) ? implode(
',', array_keys($dependency[$type])) :
'';
379 return $dependencyString;
396 $constraint = array();
397 if (is_string($dependency) && strlen($dependency)) {
398 $dependency = explode(
',', $dependency);
399 foreach ($dependency as $v) {
400 $constraint[$v] =
'';
413 $newDependencies = array();
414 $dependenciesArray = unserialize($dependencies);
415 if (is_array($dependenciesArray)) {
416 foreach ($dependenciesArray as $version) {
417 if (!empty($version[
'extensionKey'])) {
418 $newDependencies[$version[
'kind']][$version[
'extensionKey']] = $version[
'versionRange'];
422 return $newDependencies;