. */ /* * For reference, the status.xml file loads the following information: * * SimpleXMLElement Object * ( * [id] => 640de0c121f432597706ba3c50c132be211a1234 * [author] => John Doe * [deployer] => Bitbucket * [authorEmail] => john@example.com * [message] => my commit message * * [progress] => SimpleXMLElement Object * ( * ) * * [status] => Success * [statusText] => SimpleXMLElement Object * ( * ) * * [lastSuccessEndTime] => 2016-09-01T15:15:56.7740733Z * [receivedTime] => 2016-09-01T15:15:47.9334918Z * [startTime] => 2016-09-01T15:15:48.0903974Z * [endTime] => 2016-09-01T15:15:56.7740733Z * [complete] => True * [is_temp] => False * [is_readonly] => False * ) **/ require(dirname(__FILE__) . '/../classes/app-service-deployment-info.php'); // if enabled, the plugin attempts to use wincache (installed by default in // App Service) to cache the deployment information so that each admin page load // doesn't trigger an additional file system read. Use with care -- it is possible // that a deployment won't reset the cache, which would defeat the purpose of the plugin. // That's why the default, for now, is to turn caching off. if ( ! defined( 'APPSVC_USE_CACHE' ) ) { define("APPSVC_USE_CACHE", false); } if ( ! defined( 'APPSVC_DEPLOYMENT_INFO' ) ) { define("APPSVC_DEPLOYMENT_INFO_CACHE_KEY", "APPSVC_DEPLOYMENT_INFO"); } // NOTE: the following two values are specific to the Azure App Service environment // and can not (to my knowledge) be overridden by the end-user. Modify with care. if ( ! defined( 'APPSVC_ACTIVE_DEPLOYMENT_DIR' ) ) { define("APPSVC_ACTIVE_DEPLOYMENT_DIR", "D:\home\site\deployments"); } if ( ! defined( 'APPSVC_ACTIVE_DEPLOYMENT_FILE_NAME' ) ) { define("APPSVC_ACTIVE_DEPLOYMENT_FILE_NAME", "active"); } // checks a server variable to make sure we're running // on Azure App Service function appsvc_is_azure() { return array_key_exists('APP_POOL_ID', $_SERVER); } // azure app service has wincache installed // use that to cache the deployment info, if enabled function appsvc_has_wincache() { return function_exists('wincache_ucache_exists'); } // retrieves the XML deployment information for the current // deployment from cache, or disk // NOTE: this assumes the cache is cleared on server restart -- // it is not cleared explicitly function assi_get_deployment_info() { if ( APPSVC_USE_CACHE && appsvc_has_wincache() && wincache_ucache_exists(APPSVC_DEPLOYMENT_INFO_CACHE_KEY) ) { $info = wincache_ucache_get(APPSVC_DEPLOYMENT_INFO_CACHE_KEY); if ($info != NULL) { return $info; } } $deployment_id = trim(file_get_contents(APPSVC_ACTIVE_DEPLOYMENT_DIR . "/" . APPSVC_ACTIVE_DEPLOYMENT_FILE_NAME)); $xml = simplexml_load_file(APPSVC_ACTIVE_DEPLOYMENT_DIR . "/$deployment_id/status.xml"); // convert to a simple object (the XML object can't be serialized to wincache) $obj = new AppServiceDeploymentInfo($xml); if ( APPSVC_USE_CACHE && appsvc_has_wincache() ) { wincache_ucache_set(APPSVC_DEPLOYMENT_INFO_CACHE_KEY, $obj); } return $obj; } // gets deployment info from azure app service, or // an err message if this is not azure app service function appsvc_get_deployment_info() { if ( appsvc_is_azure() ) { return assi_get_deployment_info(); } else { return "Unknown"; } } // append our deployment information into the footer function appsvc_admin_footer_function($str) { $info = appsvc_get_deployment_info(); if ( is_a($info, 'AppServiceDeploymentInfo' ) ) { $time_str = strftime('%c %Z', $info->endTime); $info_html = <<