]> git.mxchange.org Git - friendica.git/commitdiff
Fix support for multiple authors and maintainers
authorArt4 <art4@wlabs.de>
Tue, 4 Feb 2025 14:35:57 +0000 (14:35 +0000)
committerArt4 <art4@wlabs.de>
Tue, 4 Feb 2025 14:35:57 +0000 (14:35 +0000)
src/Core/Addon/AddonInfo.php
src/Core/Addon/AddonProxy.php
src/Module/Admin/Addons/Details.php
tests/Unit/Core/Addon/AddonInfoTest.php

index 3f05c2e15be80f4d360bef9e7caa563936419060..ce5f07fc0f50d278247ee1f0efbaf2541990fdce 100644 (file)
@@ -24,8 +24,8 @@ final class AddonInfo
                $id          = array_key_exists('id', $info) ? (string) $info['id'] : '';
                $name        = array_key_exists('name', $info) ? (string) $info['name'] : '';
                $description = array_key_exists('description', $info) ? (string) $info['description'] : '';
-               $author      = array_key_exists('author', $info) ? self::parseContributor($info['author']) : [];
-               $maintainer  = array_key_exists('maintainer', $info) ? self::parseContributor($info['maintainer']) : [];
+               $authors     = array_key_exists('authors', $info) ? self::parseContributors($info['authors']) : [];
+               $maintainers = array_key_exists('maintainers', $info) ? self::parseContributors($info['maintainers']) : [];
                $version     = array_key_exists('version', $info) ? (string) $info['version'] : '';
                $status      = array_key_exists('status', $info) ? (string) $info['status'] : '';
 
@@ -33,32 +33,42 @@ final class AddonInfo
                        $id,
                        $name,
                        $description,
-                       $author,
-                       $maintainer,
+                       $authors,
+                       $maintainers,
                        $version,
                        $status
                );
        }
 
-       private static function parseContributor($entry): array
+       private static function parseContributors($entries): array
        {
-               if (!is_array($entry)) {
+               if (!is_array($entries)) {
                        return [];
                }
 
-               if (!array_key_exists('name', $entry)) {
-                       return [];
-               }
+               $contributors = [];
+
+               foreach ($entries as $entry) {
+                       if (!is_array($entry)) {
+                               continue;
+                       }
+
+                       if (!array_key_exists('name', $entry)) {
+                               continue;
+                       }
+
+                       $contributor = [
+                               'name' => (string) $entry['name'],
+                       ];
 
-               $contributor = [
-                       'name' => (string) $entry['name'],
-               ];
+                       if (array_key_exists('link', $entry)) {
+                               $contributor['link'] = (string) $entry['link'];
+                       }
 
-               if (array_key_exists('link', $entry)) {
-                       $contributor['link'] = (string) $entry['link'];
+                       $contributors[] = $contributor;
                }
 
-               return $contributor;
+               return $contributors;
        }
 
        private string $id = '';
@@ -67,9 +77,9 @@ final class AddonInfo
 
        private string $description = '';
 
-       private array $author = [];
+       private array $authors = [];
 
-       private array $maintainer = [];
+       private array $maintainers = [];
 
        private string $version = '';
 
@@ -79,16 +89,16 @@ final class AddonInfo
                string $id,
                string $name,
                string $description,
-               array $author,
-               array $maintainer,
+               array $authors,
+               array $maintainers,
                string $version,
                string $status
        ) {
                $this->id          = $id;
                $this->name        = $name;
                $this->description = $description;
-               $this->author      = $author;
-               $this->maintainer  = $maintainer;
+               $this->authors     = $authors;
+               $this->maintainers = $maintainers;
                $this->version     = $version;
                $this->status      = $status;
        }
@@ -108,14 +118,14 @@ final class AddonInfo
                return $this->description;
        }
 
-       public function getAuthor(): array
+       public function getAuthors(): array
        {
-               return $this->author;
+               return $this->authors;
        }
 
-       public function getMaintainer(): array
+       public function getMaintainers(): array
        {
-               return $this->maintainer;
+               return $this->maintainers;
        }
 
        public function getVersion(): string
index 31f9fa90af039168be866226094aa01005bf0210..7cbf25d9d7e6497153e116045e127ae2ded92ccf 100644 (file)
@@ -103,6 +103,14 @@ final class AddonProxy implements AddonHelper
                // add addon ID
                $data['id'] = $addonId;
 
+               // rename author to authors
+               $data['authors'] = $data['author'];
+               unset($data['author']);
+
+               // rename maintainer to maintainers
+               $data['maintainers'] = $data['maintainer'];
+               unset($data['maintainer']);
+
                return AddonInfo::fromArray($data);
        }
 
index 12fb71b59e386b0a62c2784f00f710a4eb1603e5..b7ffdd39a0a409535243c58b851e943f618d48f6 100644 (file)
@@ -94,6 +94,8 @@ class Details extends BaseAdmin
 
                $t = Renderer::getMarkupTemplate('admin/addons/details.tpl');
 
+               throw new \Exception('ff');
+
                return Renderer::replaceMacros($t, [
                        '$title'    => DI::l10n()->t('Administration'),
                        '$page'     => DI::l10n()->t('Addons'),
@@ -107,8 +109,8 @@ class Details extends BaseAdmin
                                'name'        => $addonInfo->getName(),
                                'version'     => $addonInfo->getVersion(),
                                'description' => $addonInfo->getDescription(),
-                               'author'      => $addonInfo->getAuthor(),
-                               'maintainer'  => $addonInfo->getMaintainer(),
+                               'author'      => $addonInfo->getAuthors(),
+                               'maintainer'  => $addonInfo->getMaintainers(),
                        ],
                        '$str_author'     => DI::l10n()->t('Author: '),
                        '$str_maintainer' => DI::l10n()->t('Maintainer: '),
index 12dc4747940eeb83df9cc7ad35979f488685b96b..8181dc3daf417d7a428200b1185e9454f78652f2 100644 (file)
@@ -20,8 +20,8 @@ class AddonInfoTest extends TestCase
                        'id'          => '',
                        'name'        => '',
                        'description' => '',
-                       'author     => [],
-                       'maintainer => [],
+                       'authors'     => [],
+                       'maintainers' => [],
                        'version'     => '',
                        'status'      => '',
                ];
@@ -35,8 +35,8 @@ class AddonInfoTest extends TestCase
                        'id'          => 'test',
                        'name'        => 'Test-Addon',
                        'description' => 'This is an addon for tests',
-                       'author'      => ['name' => 'Sam'],
-                       'maintainer'  => ['name' => 'Sam', 'link' => 'https://example.com'],
+                       'authors'     => [['name' => 'Sam']],
+                       'maintainers' => [['name' => 'Sam', 'link' => 'https://example.com']],
                        'version'     => '0.1',
                        'status'      => 'In Development',
                ];
@@ -47,8 +47,8 @@ class AddonInfoTest extends TestCase
                $this->assertSame($data['name'], $info->getName());
                $this->assertSame($data['description'], $info->getDescription());
                $this->assertSame($data['description'], $info->getDescription());
-               $this->assertSame($data['author'], $info->getAuthor());
-               $this->assertSame($data['maintainer'], $info->getMaintainer());
+               $this->assertSame($data['authors'], $info->getAuthors());
+               $this->assertSame($data['maintainers'], $info->getMaintainers());
                $this->assertSame($data['version'], $info->getVersion());
                $this->assertSame($data['status'], $info->getStatus());
        }