Skip to content

Commit

Permalink
Merge pull request #125 from IchHabRecht/feature-add-vendor-name
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabRecht authored May 16, 2018
2 parents 53ca140 + fba55a7 commit f791082
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 25 deletions.
63 changes: 43 additions & 20 deletions Classes/Controller/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,46 +90,51 @@ public function __construct(StorageRepository $storageRepository)
public function listAction()
{
$extensionName = $this->getExtensionName();
$vendorName = $this->getVendorName();

$files = $this->getFiles($extensionName);
$files = $this->getFiles($vendorName, $extensionName);

$this->view->assignMultiple(
[
'composerMode' => Bootstrap::usesComposerClassLoading(),
'vendorName' => $vendorName,
'extensionName' => $extensionName,
'files' => $files,
]
);
}

/**
* @param string $vendorName
* @param string $extensionName
*/
public function saveAction($extensionName = '')
public function saveAction($vendorName = '', $extensionName = '')
{
if (!empty($extensionName)) {
$backendUser = $this->getBackendUser();
$backendUser->uc['mask_export']['extensionName'] = $extensionName;
$backendUser->writeUC();
}
$vendorName = $vendorName ?: $this->getVendorName();
$extensionName = $extensionName ?: $this->getExtensionName();

$backendUser = $this->getBackendUser();
$backendUser->uc['mask_export']['vendorName'] = $vendorName;
$backendUser->uc['mask_export']['extensionName'] = $extensionName;
$backendUser->writeUC();

if ($this->request->hasArgument('submit')) {
$action = strtolower($this->request->getArgument('submit'));
if (in_array($action, ['download', 'install'])) {
$extensionName = $extensionName ?: $this->getExtensionName();
$this->redirect($action, null, null, ['extensionName' => $extensionName]);
$this->redirect($action, null, null, ['vendorName' => $vendorName, 'extensionName' => $extensionName]);
}
}

$this->redirect('list');
}

/**
* @param string $vendorName
* @param string $extensionName
*/
public function downloadAction($extensionName)
public function downloadAction($vendorName, $extensionName)
{
$files = $this->getFiles($extensionName);
$files = $this->getFiles($vendorName, $extensionName);

$zipFile = tempnam(sys_get_temp_dir(), 'zip');

Expand All @@ -152,17 +157,18 @@ public function downloadAction($extensionName)
}

/**
* @param string $vendorName
* @param string $extensionName
*/
public function installAction($extensionName)
public function installAction($vendorName, $extensionName)
{
$paths = Extension::returnInstallPaths();
if (empty($paths['Local']) || !file_exists($paths['Local'])) {
throw new \RuntimeException('Local extension install path is missing', 1500061028);
}

$extensionPath = $paths['Local'] . $extensionName;
$files = $this->getFiles($extensionName);
$files = $this->getFiles($vendorName, $extensionName);
$this->writeExtensionFilesToPath($files, $extensionPath);

$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
Expand Down Expand Up @@ -213,10 +219,24 @@ protected function getExtensionName()
}

/**
* @return string
*/
protected function getVendorName()
{
$backendUser = $this->getBackendUser();
if (!empty($backendUser->uc['mask_export']['vendorName'])) {
return $backendUser->uc['mask_export']['vendorName'];
}

return str_replace('_', '-', $this->defaultExtensionName);
}

/**
* @param string $vendorName
* @param string $extensionName
* @return array
*/
protected function getFiles($extensionName)
protected function getFiles($vendorName, $extensionName)
{
$maskConfiguration = (array)$this->storageRepository->load();

Expand All @@ -232,7 +252,7 @@ protected function getFiles($extensionName)
$aggregateCollection
)->getFiles();

$files = $this->replaceExtensionInformation($extensionName, $files);
$files = $this->replaceExtensionInformation($vendorName, $extensionName, $files);
$files = $this->sortFiles($files);

return $files;
Expand Down Expand Up @@ -272,15 +292,17 @@ protected function writeExtensionFilesToPath(array $files, $extensionPath)
}

/**
* @param string $vendorName
* @param string $extensionKey
* @param array $files
* @return array
*/
protected function replaceExtensionInformation($extensionKey, array $files)
protected function replaceExtensionInformation($vendorName, $extensionKey, array $files)
{
$newFiles = [];
foreach ($files as $file => $fileContent) {
$newFiles[$this->replaceExtensionKey($extensionKey, $file)] = $this->replaceExtensionKey(
$newFiles[$this->replaceExtensionKey($vendorName, $extensionKey, $file)] = $this->replaceExtensionKey(
$vendorName,
$extensionKey,
$fileContent
);
Expand All @@ -290,11 +312,12 @@ protected function replaceExtensionInformation($extensionKey, array $files)
}

/**
* @param string $vendorName
* @param string $extensionKey
* @param string $string
* @return string
*/
protected function replaceExtensionKey($extensionKey, $string)
protected function replaceExtensionKey($vendorName, $extensionKey, $string)
{
$camelCasedExtensionKey = GeneralUtility::underscoredToUpperCamelCase($extensionKey);
$lowercaseExtensionKey = strtolower($camelCasedExtensionKey);
Expand All @@ -311,7 +334,7 @@ protected function replaceExtensionKey($extensionKey, $string)
);
$string = preg_replace(
'/MASK/',
strtoupper($camelCasedExtensionKey),
$vendorName,
$string
);
$string = preg_replace(
Expand All @@ -331,7 +354,7 @@ protected function replaceExtensionKey($extensionKey, $string)
);
$string = preg_replace(
'/(")mask(\/)/',
'"' . str_replace('_', '-', $extensionKey) . '/',
'"' . strtolower($vendorName) . '/',
$string
);
$string = preg_replace(
Expand Down
20 changes: 18 additions & 2 deletions Resources/Private/Backend/Templates/Export/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,29 @@
<f:form action="save">
<div class="row">
<div class="form-group col-sm-4">
<label for="meta_label" class="t3js-formengine-label">
<label for="extensionName" class="t3js-formengine-label">
Extension name
</label>
<div class="t3js-formengine-field-item">
<div class="form-control-wrap">
<f:form.textfield value="" name="extensionName" placeholder="{extensionName}" title="Extension Name" id="meta_label" class="form-control" />
<f:form.textfield value="" name="extensionName" placeholder="{extensionName}" id="extensionName" title="Extension Name" class="form-control" />
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="form-group col-sm-4">
<label for="vendorName" class="t3js-formengine-label">
Vendor name
</label>
<div class="t3js-formengine-field-item">
<div class="form-control-wrap">
<f:form.textfield value="" name="vendorName" placeholder="{vendorName}" id="vendorName" title="Vendor Name" class="form-control" />
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="form-group col-sm-4">
<div class="t3js-formengine-field-item">
<div class="form-control-wrap">
<f:form.submit name="submit" value="Save" class="btn btn-success col-sm-3" />
<f:form.hidden name="submit" value="" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ abstract class AbstractExportControllerTestCase extends FunctionalTestCase
'fluid_styled_content',
];

/**
* @var string
*/
protected $vendorName = 'IchHabRecht';

/**
* @var string
*/
Expand Down Expand Up @@ -78,6 +83,7 @@ protected function setUp()

// The export stores new extension names in backend user settings, so we need a pseudo user object here
$backendUser = new BackendUserAuthentication();
$backendUser->uc['mask_export']['vendorName'] = $this->vendorName;
$backendUser->uc['mask_export']['extensionName'] = $this->extensionName;
$GLOBALS['BE_USER'] = $backendUser;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function checkFluidTemplatePathInBackendPreview()
*/
public function validateProcessedRowDataFromPageLayoutViewDrawItem()
{
$className = 'MASKEXAMPLEEXPORT\\MaskExampleExport\\Hooks\\PageLayoutViewDrawItem';
$className = 'IchHabRecht\\MaskExampleExport\\Hooks\\PageLayoutViewDrawItem';
$this->installExtension();

$this->assertTrue(class_exists($className));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function ensureExtensionNameIsReplacedInComposerJson()
}

$this->assertContains(
'"name": "mask-example-export/mask-example-export",',
'"name": "ichhabrecht/mask-example-export",',
$this->files['composer.json']
);

Expand All @@ -88,7 +88,7 @@ public function ensureExtensionNameIsReplacedInComposerJson()
);

$this->assertContains(
'"MASKEXAMPLEEXPORT\\\\MaskExampleExport\\\\": "Classes/"',
'"IchHabRecht\\\\MaskExampleExport\\\\": "Classes/"',
$this->files['composer.json']
);

Expand Down

0 comments on commit f791082

Please sign in to comment.