Fixed xf-addon:install does not accept -

Kirby

Well-known member
Affected version
2.3.0 Beta 2
Trying to install an Add-on ZIP from stdin via cat <zipfile> | php cmd.php xf-addon:install - produces the following error message
The add-on '-' could be found.
 
It was never our intention for it to be used how you're trying to, though I appreciate this is a common convention. But we don't parse the incoming arguments so the fact that it doesn't work seems like it would be an issue with symfony/console more than anything, or simply something they don't support.

Naturally, php cmd.php xf-addon:install <zipfile> will work fine.
 
Naturally, php cmd.php xf-addon:install <zipfile> will work fine.
Yeah, it does - but doing this remotely makes things a bit more complicated (than it IMHO needs to be).

Nothing that can't be dealt with (via Ansible, etc.) but being able to just fire off a single SSH command to install an Add-on would be awesome :)

But we don't parse the incoming arguments so the fact that it doesn't work seems like it would be an issue with symfony/console more than anything, or simply something they don't support.
I don't think this has anything to do with Symfony, XenForo just gets an argument and treats that as an Add-on ID or Filename - so XenForo controls the whole processing of that input:
PHP:
->addArgument(
    'id',
    InputArgument::REQUIRED,
    'Add-On ID or path to add-on zip file'
)

Just adding a few lines to AddOnActionTraitcould make this work (at least it does work for me if I patch that into the trait, unfortunately Cli Command classes can't be extended :()

PoC
Code:
*** AddOnActionTrait.php    Fri Mar 29 00:20:34 2024
--- AddOnActionTrait.php    Fri Mar 29 00:20:48 2024
***************
*** 280,285 ****
--- 280,290 ----
 
      public function isAZipFile($pathToZip)
      {
+         if ($pathToZip === '-')
+         {
+             return true;
+         }
+
          if (strtolower(pathinfo($pathToZip, PATHINFO_EXTENSION)) == 'zip'
              && file_exists($pathToZip) && is_readable($pathToZip)
          )
***************
*** 294,299 ****
--- 299,313 ----
      {
          /** @var \XF\Repository\AddOn $addOnRepo */
          $addOnRepo = \XF::repository('XF:AddOn');
+
+         if ($zipFile === '-')
+         {
+             $tempZip = \XF\Util\File::getTempFile();
+             $fp = fopen($tempZip, 'w');
+             stream_copy_to_stream(STDIN, $fp);
+             fclose($fp);
+             $zipFile = $tempZip;
+         }
 
          if (!$addOnRepo->canInstallFromArchive($error, true))
          {

Btw:
Why aren't there argument and return type hints on methods like isAZipFile?
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.3.0 Beta 3).

Change log:
Support passing a zip file into stdin into add-on CLI commands via the - argument.
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom