[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorSystemRemoveDestroyWorkflow 4 extends PhabricatorSystemRemoveWorkflow { 5 6 public function didConstruct() { 7 $this 8 ->setName('destroy') 9 ->setSynopsis(pht('Permanently destroy objects.')) 10 ->setExamples('**destroy** [__options__] __object__ ...') 11 ->setArguments( 12 array( 13 array( 14 'name' => 'force', 15 'help' => pht('Destroy objects without prompting.'), 16 ), 17 array( 18 'name' => 'objects', 19 'wildcard' => true, 20 ), 21 )); 22 } 23 24 public function execute(PhutilArgumentParser $args) { 25 $console = PhutilConsole::getConsole(); 26 27 $object_names = $args->getArg('objects'); 28 if (!$object_names) { 29 throw new PhutilArgumentUsageException( 30 pht('Specify one or more objects to destroy.')); 31 } 32 33 $object_query = id(new PhabricatorObjectQuery()) 34 ->setViewer($this->getViewer()) 35 ->withNames($object_names); 36 37 $object_query->execute(); 38 39 $named_objects = $object_query->getNamedResults(); 40 foreach ($object_names as $object_name) { 41 if (empty($named_objects[$object_name])) { 42 throw new PhutilArgumentUsageException( 43 pht('No such object "%s" exists!', $object_name)); 44 } 45 } 46 47 foreach ($named_objects as $object_name => $object) { 48 if (!($object instanceof PhabricatorDestructibleInterface)) { 49 throw new PhutilArgumentUsageException( 50 pht( 51 'Object "%s" can not be destroyed (it does not implement %s).', 52 $object_name, 53 'PhabricatorDestructibleInterface')); 54 } 55 } 56 57 $console->writeOut( 58 "<bg:red>**%s**</bg>\n\n", 59 pht(' IMPORTANT: OBJECTS WILL BE PERMANENTLY DESTROYED! ')); 60 61 $console->writeOut( 62 pht( 63 "There is no way to undo this operation or ever retrieve this data.". 64 "\n\n". 65 "These %s object(s) will be **completely destroyed forever**:". 66 "\n\n", 67 new PhutilNumber(count($named_objects)))); 68 69 foreach ($named_objects as $object_name => $object) { 70 $console->writeOut( 71 " - %s (%s)\n", 72 $object_name, 73 get_class($object)); 74 } 75 76 $force = $args->getArg('force'); 77 if (!$force) { 78 $ok = $console->confirm( 79 pht( 80 'Are you absolutely certain you want to destroy these %s object(s)?', 81 new PhutilNumber(count($named_objects)))); 82 if (!$ok) { 83 throw new PhutilArgumentUsageException( 84 pht('Aborted, your objects are safe.')); 85 } 86 } 87 88 $console->writeOut("%s\n", pht('Destroying objects...')); 89 90 foreach ($named_objects as $object_name => $object) { 91 $console->writeOut( 92 pht( 93 "Destroying %s **%s**...\n", 94 get_class($object), 95 $object_name)); 96 97 id(new PhabricatorDestructionEngine()) 98 ->destroyObject($object); 99 } 100 101 $console->writeOut( 102 "%s\n", 103 pht( 104 'Permanently destroyed %s object(s).', 105 new PhutilNumber(count($named_objects)))); 106 107 return 0; 108 } 109 110 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |