protected function ContentSynchronizerManager::setDestination in Content Synchronizer 3.x
Update destination.
Parameters
string $destination: The destination.
string $tempArchive: The real path archive.
Return value
string The final destination.
1 call to ContentSynchronizerManager::setDestination()
- ContentSynchronizerManager::createExportFile in src/
Service/ ContentSynchronizerManager.php - Create a tar.gz file.
File
- src/
Service/ ContentSynchronizerManager.php, line 324
Class
- ContentSynchronizerManager
- ContentSynchronizerManager service.
Namespace
Drupal\content_synchronizer\ServiceCode
protected function setDestination($destination, $tempArchive) {
$absolutePath = NULL;
$resultDestination = NULL;
if ($destination !== '') {
$baseName = basename($destination);
$path = str_replace($baseName, '', $destination);
// Relative.
if ($destination[0] !== '/') {
$path = $destination[0] === '.' ? substr($path, 1) : $path;
// Get options.
$root = getopt('r:')['r'] ?: getopt('', [
'root:',
])['root'];
if ($root) {
$absolutePath = $root . '/' . $path;
}
elseif ($_SERVER && array_key_exists('PWD', $_SERVER)) {
$absolutePath = $_SERVER['PWD'] . '/' . $path;
}
}
else {
$absolutePath = $destination;
}
if ($absolutePath) {
if (!is_dir($absolutePath)) {
$this->fileSystem
->prepareDirectory($absolutePath, FileSystemInterface::CREATE_DIRECTORY);
}
$resultDestination = $absolutePath . '/' . $baseName;
}
}
// Try destination.
copy($tempArchive, $resultDestination);
if (!file_exists($resultDestination)) {
// Try root.
$resultDestination = $this->appRoot . '/' . ($baseName ?: basename($tempArchive));
copy($tempArchive, $resultDestination);
if (!file_exists($resultDestination)) {
// Destination is tmp.
$resultDestination = $tempArchive;
}
}
return $resultDestination;
}