Last active
December 3, 2020 15:30
-
-
Save seedprod/53af14fc9fe3f8297753e8b285430645 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// we have a product upload record in our db. That upload record has things like: | |
//slug, zipfile, current_verison, wordpress_version_required, test_to, upgrade_notice etc | |
// when a update request comes in we run our checks. | |
// for example if we are checking for a legacy version | |
$is_legacy = false; | |
$latest_legacy_version = '5.12.8'; | |
if(version_compare( '6.0.0' , $incoming_version ) ){ | |
$is_legacy = true; | |
} | |
// If we only want to give to 10% of the of the incoming request, our licnese id are sequential so we check the last digit value | |
// not sure how scientific that is but say we only want to do 10%, I say if the licnese id ends with a 1, | |
// If we want to do 20% the we check if in array like array(1,2); | |
// for example if we are checking for a legacy version | |
$license_id = (string)2468; // type casting int to string | |
$part_of_sample = false; | |
$allowed_range = array(1,2) | |
$sample_legacy_version = '5.12.8'; | |
if(in_array($license_id[strlen($license_id)-1],$allowed_range) ){ | |
$part_of_sample = true; | |
} | |
// When we get the download we look to see if we have set any flags | |
// then if a flag is set pull an altenate variable form the db record | |
foreach ($product->uploads as $u) { | |
if ($u->slug == $slug_short) { | |
$new_version = $u->current_version; | |
// check for flags | |
if($is_legacy){ | |
$new_version = $latest_legacy_version; | |
} | |
$required_version = trim($u->plugin_version_required); | |
$s3client = Storage::disk('s3legacy')->getDriver()->getAdapter()->getClient(); | |
$s3cmd = $s3client->getCommand('GetObject', [ | |
'Bucket' => 'secure.seedprod.com', | |
'Key' => $slug_short.'-'.$new_version.'.zip' | |
]); | |
$s3request = $s3client->createPresignedRequest($s3cmd, '+8 hours'); | |
$download_link = (string) $s3request->getUri(); | |
$name = $u->name; | |
$requires = $u->requires; | |
if(!empty($u->test_to)){ | |
$tested = $u->test_to; | |
} | |
$last_updated = $u->last_updated; | |
$upgrade_notice = $u->upgrade_notice; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment