Summary: Ref T2015. Moves a bunch of raw object loads into modern policy-aware queries. Also straightens out the Log and Lease policies a little bit: there are legitimate states where these objects are not attached to a resource (particularly, while a lease is being acquired). Handle these more gracefully. Test Plan: Lint / browsed stuff. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2015 Differential Revision: https://secure.phabricator.com/D7836
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
final class DrydockManagementCloseWorkflow
 | 
						|
  extends DrydockManagementWorkflow {
 | 
						|
 | 
						|
  public function didConstruct() {
 | 
						|
    $this
 | 
						|
      ->setName('close')
 | 
						|
      ->setSynopsis('Close a resource.')
 | 
						|
      ->setArguments(
 | 
						|
        array(
 | 
						|
          array(
 | 
						|
            'name'      => 'ids',
 | 
						|
            'wildcard'  => true,
 | 
						|
          ),
 | 
						|
        ));
 | 
						|
  }
 | 
						|
 | 
						|
  public function execute(PhutilArgumentParser $args) {
 | 
						|
    $console = PhutilConsole::getConsole();
 | 
						|
 | 
						|
    $ids = $args->getArg('ids');
 | 
						|
    if (!$ids) {
 | 
						|
      throw new PhutilArgumentUsageException(
 | 
						|
        "Specify one or more resource IDs to close.");
 | 
						|
    }
 | 
						|
 | 
						|
    $viewer = PhabricatorUser::getOmnipotentUser();
 | 
						|
 | 
						|
    $resources = id(new DrydockResourceQuery())
 | 
						|
      ->setViewer($viewer)
 | 
						|
      ->withIDs($ids)
 | 
						|
      ->execute();
 | 
						|
 | 
						|
    foreach ($ids as $id) {
 | 
						|
      $resource = idx($resources, $id);
 | 
						|
      if (!$resource) {
 | 
						|
        $console->writeErr("Resource %d does not exist!\n", $id);
 | 
						|
      } else if ($resource->getStatus() != DrydockResourceStatus::STATUS_OPEN) {
 | 
						|
        $console->writeErr("Resource %d is not 'open'!\n", $id);
 | 
						|
      } else {
 | 
						|
        $resource->closeResource();
 | 
						|
        $console->writeErr("Closed resource %d.\n", $id);
 | 
						|
      }
 | 
						|
    }
 | 
						|
 | 
						|
  }
 | 
						|
 | 
						|
}
 |