@@ -16,7 +16,6 @@ abstract class Terminus_Command {
1616 public $ cache ;
1717 public $ session ;
1818 public $ sites ;
19- static $ instance = false ;
2019
2120 protected $ _func ;
2221 protected $ _siteInfo ;
@@ -27,68 +26,6 @@ public function __construct() {
2726 $ this ->cache = Terminus::get_cache ();
2827 $ this ->session = Session::instance ();
2928 $ this ->sites = $ this ->cache ->get_data ('sites ' );
30- self ::$ instance = $ this ;
31- }
32-
33- public static function instance () {
34- if (!self ::$ instance ) {
35- Terminus::error ("No valid instance available " );
36- }
37- return self ::$ instance ;
38- }
39-
40- /**
41- * Helper code to grab sites and manage local cache.
42- */
43- protected function fetch_sites ( $ nocache = false ) {
44- if (!$ this ->sites || $ nocache ) {
45- $ this ->_fetch_sites ();
46- }
47- return $ this ->sites ;
48- }
49-
50- /**
51- * Actually go out and get the sites.
52- */
53- protected function _fetch_sites () {
54- Terminus::log ('Fetching site list from Pantheon ' );
55-
56- $ request = self ::request ( 'user ' , Session::getValue ('user_uuid ' ), 'sites ' , 'GET ' , Array ('hydrated ' => true ));
57-
58- # TODO: handle errors well.
59- $ sites = $ request ['data ' ];
60- $ this ->cache ->put_data ( 'sites ' , $ sites );
61- $ this ->sites = $ sites ;
62- return $ sites ;
63- }
64-
65- /**
66- * Helper function to grab a single site's data from cache if possible.
67- */
68- protected function fetch_site ( $ site_name , $ nocache = false ) {
69- if ( $ this ->_fetch_site ($ site_name ) !== false && !$ nocache ) {
70- return $ this ->_fetch_site ($ site_name );
71- }
72- # No? Refresh that list.
73- $ this ->_fetch_sites ();
74- if ( $ this ->_fetch_site ($ site_name ) !== false ) {
75- return $ this ->_fetch_site ($ site_name );
76- }
77- Terminus::error ("The site named '%s' does not exist. Run `terminus sites show` for a list of sites. " , array ($ site_name ));
78- }
79-
80- /**
81- * Private function to deal with our data object for sites and return one
82- * by name that includes its uuid.
83- */
84- private function _fetch_site ( $ site_name ) {
85- foreach ($ this ->sites as $ site_uuid => $ data ) {
86- if ( $ data ->information ->name == $ site_name ) {
87- $ data ->information ->site_uuid = $ site_uuid ;
88- return $ data ->information ;
89- }
90- }
91- return false ;
9229 }
9330
9431 /**
@@ -177,18 +114,6 @@ public static function download($url, $target) {
177114 }
178115 }
179116
180- protected function _validateSiteUuid ($ site ) {
181- if (\Terminus \Utils \is_valid_uuid ($ site ) && property_exists ($ this ->sites , $ site )){
182- $ this ->_siteInfo =& $ this ->sites [$ site ];
183- $ this ->_siteInfo ->site_uuid = $ site ;
184- } elseif ($ this ->_siteInfo = $ this ->fetch_site ($ site )) {
185- $ site = $ this ->_siteInfo ->site_uuid ;
186- } else {
187- Terminus::error ("Unable to locate the requested site. " );
188- }
189- return $ site ;
190- }
191-
192117 protected function _constructTableForResponse ($ data ,$ headers = array ()) {
193118 $ table = new \cli \Table ();
194119 if (is_object ($ data )) {
@@ -241,6 +166,7 @@ protected function _constructTableForResponse($data,$headers = array()) {
241166 * @param $object_id string -- coresponding id
242167 * @param $workflow_id string -- workflow to wait on
243168 *
169+ * @deprecated Use new WorkFlow() object instead
244170 * Example: $this->waitOnWorkflow( "sites", "68b99b50-8942-4c66-b7e3-22b67445f55d", "e4f7e832-5644-11e4-81d4-bc764e111d20");
245171 */
246172 protected function waitOnWorkflow ( $ object_name , $ object_id , $ workflow_id ) {
@@ -277,60 +203,6 @@ protected function waitOnWorkflow( $object_name, $object_id, $workflow_id ) {
277203 unset($ workflow );
278204 }
279205
280-
281- protected function _handleEnvArg (&$ args , $ assoc_args = array ()) {
282- if (array_key_exists ("env " , $ assoc_args )) {
283- $ this ->_getEnvBindings ($ args , $ assoc_args );
284- } else {
285- Terminus::error ("Please specify the site => environment with --env=<environment> option. " );
286- }
287-
288- if (!is_object ($ this ->_bindings )) {
289- if (array_key_exists ("debug " , $ assoc_args )){
290- $ this ->_debug (get_defined_vars ());
291- }
292- Terminus::error ("Unable to obtain the bindings for the requested environment. \n\n" );
293- } else {
294- if (property_exists ($ this ->_bindings , $ assoc_args ['env ' ])) {
295- $ this ->_env = $ assoc_args ['env ' ];
296- } else {
297- Terminus::error ("The requested environment either does not exist or you don't have access to it. " );
298- }
299- }
300- }
301-
302- protected function _getEnvBindings (&$ args , $ assoc_args ) {
303- $ b = self ::request ("site " , $ this ->_siteInfo ->site_uuid , 'environments/ ' . $ this ->_env .'/bindings ' , "GET " );
304- if (!empty ($ b ) && is_array ($ b ) && array_key_exists ("data " , $ b )) {
305- $ this ->_bindings = $ b ['data ' ];
306- }
307- }
308-
309- protected function _execute ( array $ args = array () , array $ assoc_args = array () ){
310- $ success = $ this ->{$ this ->_func }( $ args , $ assoc_args );
311- if (array_key_exists ("debug " , $ assoc_args )){
312- $ this ->_debug (get_defined_vars ());
313- }
314- if (!empty ($ success )){
315- if (is_array ($ success ) && array_key_exists ("data " , $ success )) {
316- if (array_key_exists ("json " , $ assoc_args )) {
317- echo \Terminus \Utils \json_dump ($ success ["data " ]);
318- } elseif (array_key_exists ("bash " , $ assoc_args )) {
319- echo \Terminus \Utils \bash_out ($ success ['data ' ]);
320- } else {
321- $ this ->_constructTableForResponse ($ success ['data ' ]);
322- }
323- } elseif (is_string ($ success )) {
324- echo Terminus::line ($ success );
325- }
326- } else {
327- if (array_key_exists ("debug " , $ assoc_args )){
328- $ this ->_debug (get_defined_vars ());
329- }
330- Terminus::error ("There was an error attempting to execute the requested task. \n\n" );
331- }
332- }
333-
334206 protected function handleDisplay ($ data ,$ args = array (), $ headers = null ) {
335207 if (array_key_exists ("json " , $ args ) OR Terminus::get_config ('json ' ) )
336208 echo \Terminus \Utils \json_dump ($ data );
@@ -340,9 +212,4 @@ protected function handleDisplay($data,$args = array(), $headers = null) {
340212 $ this ->_constructTableForResponse ((array )$ data ,$ headers );
341213 }
342214
343- protected function _debug ($ vars ) {
344- Terminus::line (print_r ($ this , true ));
345- Terminus::line (print_r ($ vars , true ));
346- }
347-
348215}
0 commit comments