public static function PublishSiteJSON($siteId) { $site = Site::GetBySiteId($siteId); $arr = Publish::CreateSiteJSON($site); // encode to json $encoded = json_encode($arr); $dest = SITES_LOCATION . '/' . $site['FriendlyId'] . '/data/'; Utilities::SaveContent($dest, 'site.json', $encoded); }
public static function DeploySite($siteId) { // get a reference to the site $site = Site::GetBySiteId($siteId); // create AWS client $client = Aws\S3\S3Client::factory(array('key' => S3_KEY, 'secret' => S3_SECRET, 'region' => S3_LOCATION)); $bucket = $site['Bucket']; $bucket_www = 'www.' . $site['Bucket']; // create a bucket if it doesn't already exist S3::CreateBucket($bucket); // set local director $local_dir = SITES_LOCATION . '/' . $site['FriendlyId']; // prefix $keyPrefix = ''; // set permissions $options = array('params' => array('ACL' => 'public-read'), 'concurrency' => 20, 'debug' => true); // sync folders, #ref: http://blogs.aws.amazon.com/php/post/Tx2W9JAA7RXVOXA/Syncing-Data-with-Amazon-S3 $client->uploadDirectory($local_dir, $bucket, $keyPrefix, $options); // get json for the site $json = json_encode(Publish::CreateSiteJSON($site, 'S3')); // deploy an updated site.json $result = $client->putObject(array('Bucket' => $bucket, 'Key' => 'data/site.json', 'Body' => $json, 'ContentType' => 'application/json', 'ACL' => 'public-read', 'StorageClass' => 'REDUCED_REDUNDANCY')); /* // #support for S3 ANAME // #ref: http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.S3.S3Client.html#_createBucket $result = $client->createBucket(array( 'Bucket' => $bucket_www, 'ACL' => 'public-read' )); // enable hosting for the bucket $result = $client->putBucketWebsite(array( // Bucket is required 'Bucket' => $bucket_www, 'RedirectAllRequestsTo' => array( 'HostName' => $bucket ))); */ }