Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Classes/FileHasher/ChangedEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,19 @@ public function clone(): ChangedEntry
$changedEntry->type = $this->type;
return $changedEntry;
}

public static function typeToString(int $type): string
{
if ($type === self::TYPE_UNCHANGED) {
return 'unchanged';
} elseif ($type === self::TYPE_NEW) {
return 'new';
} elseif ($type === self::TYPE_DELETED) {
return 'deleted';
} elseif ($type === self::TYPE_CHANGED) {
return 'changed';
}

return 'unkown type';
}
}
25 changes: 25 additions & 0 deletions src/Classes/Helpers/FileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,29 @@ public static function containsAllFiles($files, $baseDirectory): bool
}
return true;
}

public static function deletePathIsEmpty(string $path): void
{
if (file_exists($path) && !is_dir($path)) {
return;
}

if (file_exists($path) && is_dir($path) && !self::isDirEmpty($path)) {
return;
}

if (file_exists($path) && is_dir($path) && self::isDirEmpty($path)) {
rmdir($path);
}

self::deletePathIsEmpty(dirname($path));
}

public static function isDirEmpty(string $path): bool
{
if (!is_readable($path)) {
return false;
}
return (count(scandir($path)) === 2);
}
}
33 changes: 31 additions & 2 deletions src/Classes/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class Module extends ModuleInfo
*/
private array $srcFilePaths;

/**
* @var string[]
*/
private array $srcMmlcFilePaths;

/**
* @var bool
*/
Expand Down Expand Up @@ -235,7 +240,7 @@ public function setReadmePath(string $readmePath): void
}

/**
* Liefert ein Array mit Dateienpfaden, die sich in 'new_files'
* Liefert ein Array mit Dateienpfaden, die sich in 'src'
* befinden.
*
* Beispiel: [
Expand All @@ -254,6 +259,20 @@ public function setSrcFilePaths(array $value): void
$this->srcFilePaths = $value;
}

/**
* Liefert ein Array mit Dateienpfaden, die sich in 'src-mmlc'
* befinden.
*/
public function getSrcMmlcFilePaths(): array
{
return $this->srcMmlcFilePaths;
}

public function setSrcMmlcFilePaths(array $value): void
{
$this->srcMmlcFilePaths = $value;
}

/**
* Liefert true, wenn es sich um ein Remote Modul handelt.
*/
Expand Down Expand Up @@ -296,13 +315,23 @@ public function getUrlOrLocalRootPath(): string
/**
* HIER FEHLT EINE BESCHREIBUNG
*
* /Modules/{VENDOR-NAME}/{MODULE-NAME}/new_files
* /Modules/{VENDOR-NAME}/{MODULE-NAME}/src
*/
public function getSrcRootPath(): string
{
return $this->getModulePath() . '/' . $this->getSourceDir();
}

/**
* HIER FEHLT EINE BESCHREIBUNG
*
* /Modules/{VENDOR-NAME}/{MODULE-NAME}/src-mmlc
*/
public function getSrcMmlcRootPath(): string
{
return $this->getModulePath() . '/' . $this->getSourceMmlcDir();
}

/**
* HIER FEHLT EINE BESCHREIBUNG
*
Expand Down
19 changes: 15 additions & 4 deletions src/Classes/ModuleChangeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class ModuleChangeManager
*/
public static function getChangedFiles(Module $module): ChangedEntryCollection
{
if ($module->getArchiveName() === 'robinthehood/modified-std-module') {
$a = 1;
}

$hashFileLoader = new HashFileLoader();
$hashFileLoader->setDefaultScope(ModuleHasher::SCOPE_SHOP_ROOT);
$hashFile = $hashFileLoader->load($module->getHashPath());
Expand Down Expand Up @@ -96,15 +100,22 @@ public static function getFileChanges(Module $module, ChangedEntry $changedEntry
$changedEntry->hashEntryA->scope === ModuleHasher::SCOPE_SHOP_ROOT
|| $changedEntry->hashEntryA->scope === ModuleHasher::SCOPE_MODULE_SRC
) {
$moduleSrcFilePath = $module->getLocalRootPath() . $module->getSrcRootPath() . '/' . $changedEntry->hashEntryA->file;
$installedFilePath = App::getShopRoot() . '/' . ModulePathMapper::mmlcToShop($changedEntry->hashEntryA->file);
$moduleSrcFilePath =
$module->getLocalRootPath() . $module->getSrcRootPath() . '/' . $changedEntry->hashEntryA->file;
$installedFilePath =
App::getShopRoot() . '/' . ModulePathMapper::moduleSrcToShopRoot($changedEntry->hashEntryA->file);
} elseif (
$changedEntry->hashEntryA->scope === ModuleHasher::SCOPE_SHOP_VENDOR_MMLC
|| $changedEntry->hashEntryA->scope === ModuleHasher::SCOPE_MODULE_SRC_MMLC
) {
// TODO
$moduleSrcFilePath = '';
$installedFilePath = '';
$moduleSrcFilePath =
$module->getLocalRootPath() . $module->getSrcMmlcRootPath() . '/' . $changedEntry->hashEntryA->file;
$installedFilePath =
App::getShopRoot() . '/' . ModulePathMapper::moduleSrcMmlcToShopVendorMmlc(
$changedEntry->hashEntryA->file,
$module->getArchiveName()
);
}


Expand Down
2 changes: 2 additions & 0 deletions src/Classes/ModuleConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static function convertToArray(Module $module): array
'name' => $module->getName(),
'archiveName' => $module->getArchiveName(),
'sourceDir' => $module->getSourceDir(),
'sourceMmlcDir' => $module->getSourceMmlcDir(),
'version' => $module->getVersion(),
'shortDescription' => $module->getShortDescription(),
'description' => $module->getDescription(),
Expand Down Expand Up @@ -50,6 +51,7 @@ public static function convertToArray(Module $module): array
'changelogPath' => $module->getChangelogPath(),
'readmePath' => $module->getReadmePath(),
'srcFilePaths' => $module->getSrcFilePaths(),
'srcMmlcFilePaths' => $module->getSrcMmlcFilePaths(),
'isRemote' => $module->isRemote(),
'isLoadable' => $module->isLoadable()
];
Expand Down
67 changes: 37 additions & 30 deletions src/Classes/ModuleCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,38 @@ public function createFolders($archiveName, $fileName, $vendorName, $moduleNameC
file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/docs/usage.md', '');
file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/changelog.md', '');

@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/admin');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/admin/includes');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/admin/includes/extra');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/admin/includes/modules');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/admin/includes/modules/system');
file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/new_files/admin/includes/modules/system/' . $fileName, '');

@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/includes');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/includes/extra');

@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/german');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/german/modules');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/german/modules/system');
file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/german/modules/system/' . $fileName, '');

@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/english');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/english/modules');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/english/modules/system');
file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/english/modules/system/' . $fileName, '');

@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/vendor-no-composer');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/vendor-no-composer/' . $vendorName);
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/vendor-no-composer/' . $vendorName . '/' . $moduleNameCamelCase);
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/new_files/vendor-no-composer/' . $vendorName . '/' . $moduleNameCamelCase . '/Classes');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/src');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/admin');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/admin/includes');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/admin/includes/extra');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/admin/includes/modules');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/admin/includes/modules/system');
file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/src/admin/includes/modules/system/' . $fileName, '');

@mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/includes');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/includes/extra');

@mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/lang');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/lang/german');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/lang/german/modules');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/lang/german/modules/system');
file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/src/lang/german/modules/system/' . $fileName, '');

@mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/lang/english');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/lang/english/modules');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/src/lang/english/modules/system');
file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/src/lang/english/modules/system/' . $fileName, '');

@mkdir(App::getModulesRoot() . '/' . $archiveName . '/src-mmlc/vendor-no-composer');
@mkdir(App::getModulesRoot() . '/' . $archiveName . '/src-mmlc/Classes');
}

public function createModuleInfoJsonFile($archiveName, $moduleName)
{
$info = [
'name' => $moduleName,
'archiveName' => $archiveName,
'sourceDir' => 'new_files',
'sourceDir' => 'src',
'version' => 'auto',

'shortDescription' => 'Kurzbeschreibung für ' . $moduleName,
Expand All @@ -104,6 +102,15 @@ public function createModuleInfoJsonFile($archiveName, $moduleName)

'modifiedCompatibility' => [
'2.0.4.2'
],

"mmlc" => [
"version" => "^1.21.0"
],

"php" => [
"version" => "^7.4 || ^8.0",
"ext" => []
]
];

Expand Down Expand Up @@ -145,7 +152,7 @@ public function remove()
}
';

\file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/new_files/admin/includes/modules/system/' . $fileName, $content);
\file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/src/admin/includes/modules/system/' . $fileName, $content);
}

public function createSystemModuleLanguageDeFile($archiveName, $fileName, $moduleConstName, $vendorName)
Expand All @@ -158,7 +165,7 @@ public function createSystemModuleLanguageDeFile($archiveName, $fileName, $modul
define(\'' . $moduleConstName . '_STATUS_DESC\', \'\');
';

\file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/german/modules/system/' . $fileName, $content);
\file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/src/lang/german/modules/system/' . $fileName, $content);
}

public function createSystemModuleLanguageEnFile($archiveName, $fileName, $moduleConstName, $vendorName)
Expand All @@ -171,6 +178,6 @@ public function createSystemModuleLanguageEnFile($archiveName, $fileName, $modul
define(\'' . $moduleConstName . '_STATUS_DESC\', \'\');
';

\file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/new_files/lang/english/modules/system/' . $fileName, $content);
\file_put_contents(App::getModulesRoot() . '/' . $archiveName . '/src/lang/english/modules/system/' . $fileName, $content);
}
}
14 changes: 12 additions & 2 deletions src/Classes/ModuleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

class ModuleFactory
{
private const DIR_MODULE_SRC = 'src';
private const DIR_MODULE_SRC_MMLC = "src-mmlc";

public static function createFromPath(string $path): Module
{
$moduleInfoJsonPath = $path . '/moduleinfo.json';
Expand All @@ -35,10 +38,14 @@ public static function createFromPath(string $path): Module
throw new \RuntimeException('Can not parse ' . $moduleInfoJsonPath);
}

$sourceDir = $array['sourceDir'] ?? self::DIR_MODULE_SRC;
$sourceMmlcDir = $array['sourceMmlcDir'] ?? self::DIR_MODULE_SRC_MMLC;

$modulePath = FileHelper::stripBasePath(App::getRoot(), $path);
$category = $array['category'] ?? '';
$localRootPath = App::getRoot();
$absSrcRootPath = $localRootPath . $modulePath . '/' . $array['sourceDir'];
$absSrcRootPath = $localRootPath . $modulePath . '/' . $sourceDir;
$absSrcMmlcRootPath = $localRootPath . $modulePath . '/' . $sourceMmlcDir;

$array['localRootPath'] = $localRootPath;
$array['urlRootPath'] = ServerHelper::getUri();
Expand All @@ -49,6 +56,7 @@ public static function createFromPath(string $path): Module
$array['changelogPath'] = self::createChangelogPath($modulePath, $path);
$array['readmePath'] = self::createReadmePath($modulePath, $path);
$array['srcFilePaths'] = self::createSrcFilePaths($absSrcRootPath);
$array['srcMmlcFilePaths'] = self::createSrcFilePaths($absSrcMmlcRootPath);
$array['isRemote'] = false;

$module = self::createFromArray($array);
Expand All @@ -68,7 +76,8 @@ public static function createFromArray(array $array): Module
// ModuleInfo
$module->setName($array['name'] ?? '');
$module->setArchiveName($array['archiveName'] ?? '');
$module->setSourceDir($array['sourceDir'] ?? 'new_files');
$module->setSourceDir($array['sourceDir'] ?? self::DIR_MODULE_SRC);
$module->setSourceMmlcDir($array['sourceMmlcDir'] ?? self::DIR_MODULE_SRC_MMLC);
$module->setVersion($array['version'] ?? 'auto');
$module->setShortDescription($array['shortDescription'] ?? '');
$module->setDescription($array['description'] ?? '');
Expand All @@ -95,6 +104,7 @@ public static function createFromArray(array $array): Module
$module->setChangelogPath($array['changelogPath'] ?? '');
$module->setReadmePath($array['readmePath'] ?? '');
$module->setSrcFilePaths($array['srcFilePaths'] ?? []);
$module->setSrcMmlcFilePaths($array['srcMmlcFilePaths'] ?? []);
$module->setRemote($array['isRemote'] ?? false);
$module->setLoadable($array['isLoadable'] ?? false);

Expand Down
30 changes: 11 additions & 19 deletions src/Classes/ModuleHasher/ModuleHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(FileHasherInterface $fileHasher)
}

/**
* <SHOPROOT>/Module/<VENDOR>/<MODULE>/<SRC>/...
* /../<SHOPROOT>/Module/<VENDOR>/<MODULE>/<SRC>/...
*/
public function createModuleSrcHashes(Module $module): HashEntryCollection
{
Expand All @@ -45,41 +45,33 @@ public function createModuleSrcHashes(Module $module): HashEntryCollection
}

/**
* <SHOPROOT>/Module/<VENDOR>/<MODULE>/<SRC-MMLC>/...
* /../<SHOPROOT>/Module/<VENDOR>/<MODULE>/<SRC-MMLC>/...
*/
public function createModuleSrcMmlcHashes(Module $module): HashEntryCollection
{
return new HashEntryCollection([]);

// TODO: Warte auf feat/vendor-mmlc
// $files = $module->getSrcMmlcFilePaths();
// $root = $module->getLocalRootPath() . $module->getSrcMmlcRootPath() . '/';
// return $this->fileHasher->createHashes($files, $root, self::SCOPE_MODULE_SRC_MMLC);
$files = $module->getSrcMmlcFilePaths();
$root = $module->getLocalRootPath() . $module->getSrcMmlcRootPath() . '/';
return $this->fileHasher->createHashes($files, $root, self::SCOPE_MODULE_SRC_MMLC);
}

/**
* <SHOPROOT>/...
* /.../<SHOPROOT>/...
*/
public function createShopRootHashes(Module $module): HashEntryCollection
{
$files = $module->getSrcFilePaths();
$root = App::getShopRoot();
$files = ModulePathMapper::mmlcPathsToShopPaths($files);
//$files = ModulePathMapper::srcPathsToShopPaths($files);
$files = ModulePathMapper::allModuleSrcToShopRoot($files);
return $this->fileHasher->createHashes($files, $root, self::SCOPE_SHOP_ROOT);
}

/**
* <SHOPROOT>/vendor-mmlc/<VENDOR>/<MODULE>/...
* /.../<SHOPROOT>/vendor-mmlc/<VENDOR-NAME>/<MODULE-NAME>/...
*/
public function createShopVendorMmlcHashes(Module $module): HashEntryCollection
{
return new HashEntryCollection([]);

// TODO: Warte auf feat/vendor-mmlc
// $files = $module->getSrcMmlcFilePaths();
// $root = App::getShopRoot();
// $files = ModulePathMapper::srcMmlcPathsToVendorMmlcPaths($files);
// return $this->fileHasher->createHashes($files, $root, self::SCOPE_SHOP_VENDOR_MMLC);
$files = $module->getSrcMmlcFilePaths();
$root = App::getShopRoot() . '/' . ModulePathMapper::moduleSrcMmlcToShopVendorMmlc('/', $module->getArchiveName());
return $this->fileHasher->createHashes($files, $root, self::SCOPE_SHOP_VENDOR_MMLC);
}
}
Loading