@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at recaptime-dev/main 65 lines 1.4 kB view raw
1#!/usr/bin/env php 2<?php 3 4$root = dirname(dirname(dirname(__FILE__))); 5require_once $root.'/scripts/__init_script__.php'; 6 7$args = new PhutilArgumentParser($argv); 8$args->setTagline(pht('load files as image macros')); 9$args->setSynopsis(pht(<<<EOHELP 10**add_macro.php** __image__ [--as __name__] 11 Add an image macro. This can be useful for importing a large number 12 of macros. 13EOHELP 14)); 15$args->parseStandardArguments(); 16 17$args->parse( 18 array( 19 array( 20 'name' => 'as', 21 'param' => 'name', 22 'help' => pht( 23 'Use a specific name instead of the first part of the image name.'), 24 ), 25 array( 26 'name' => 'more', 27 'wildcard' => true, 28 ), 29 )); 30 31$more = $args->getArg('more'); 32if (count($more) !== 1) { 33 $args->printHelpAndExit(); 34} 35 36$path = head($more); 37$data = Filesystem::readFile($path); 38 39$name = $args->getArg('as'); 40if ($name === null) { 41 $name = head(explode('.', basename($path))); 42} 43 44$existing = id(new PhabricatorFileImageMacro())->loadOneWhere( 45 'name = %s', 46 $name); 47if ($existing) { 48 throw new Exception(pht("A macro already exists with the name '%s'!", $name)); 49} 50 51$file = PhabricatorFile::newFromFileData( 52 $data, 53 array( 54 'name' => basename($path), 55 'canCDN' => true, 56 )); 57 58$macro = id(new PhabricatorFileImageMacro()) 59 ->setFilePHID($file->getPHID()) 60 ->setName($name) 61 ->save(); 62 63$id = $file->getID(); 64 65echo pht("Added macro '%s' (%s).", $name, "F{$id}")."\n";