11 $monLibrary= dirname(__FILE__) .
"/../library";
12 $sharedLibrary= dirname(__FILE__) .
"/../../shared/library";
13 $datafolder = dirname(__FILE__) .
"/appreportdata";
14 $tmpdir =
"/home/homecu/tmp/appreportdata/";
15 $playStoreBucket =
"pubsite_prod_rev_03651443995346945786";
18 require_once(
"$monLibrary/cu_top.i");
19 require_once(
"$monLibrary/ck_hticket.i");
20 require_once(
"$sharedLibrary/hcuCommon.i");
21 require_once(
"$sharedLibrary/hcuEnv.i");
22 require_once(
"$sharedLibrary/cu_flagconst.i");
23 require
'/var/www/vendor/autoload.php';
24 use Google\Cloud\Storage\StorageClient;
26 if (!CheckPerm($link, $Hu, basename($_SERVER[
'SCRIPT_NAME']), $_SERVER[
'REMOTE_ADDR'])) {
27 header(
"Location: /hcuadm/hcu_noperm.prg");
31 function returnBucket(){
32 global $playStoreBucket;
34 $GPStatsCredentialsPath= GetGPStatsCredentialsPath();
36 $credentials_json = GetAwsCertFile($GPStatsCredentialsPath,
38 HOMECU_DOCK_CERT_DIR);
39 if ($credentials_json ==
'') {
40 throw new Exception(
"[gpstats] Credentials could not be loaded!");
44 'keyFilePath' => $credentials_json,
45 'projectId' =>
'homecu-gpstats',
47 $storage =
new StorageClient($config);
49 $bucket = $storage->bucket($playStoreBucket);
53 function downloadCu($cucode, $date, $report_type, $file_version){
55 $bucket = returnBucket();
56 $return_array=array();
58 $return_array[
'error_message']=
'';
60 $object = $bucket->object(
'stats/' . $report_type .
'/' . $report_type .
'_com.homecu.' . $cucode .
"_" . $date . $file_version);
63 if($object->exists()==
false){
64 $return_array[
"success"] = FALSE;
65 $return_array[
"error_message"] =
"CU not found in Google database";
70 $localdir = $tmpdir . $report_type . $date .
"/";
71 if (!is_dir($localdir)){
72 mkdir($localdir, 2770,
true);
75 $object->downloadToFile($localdir . $cucode .
".csv");
76 $return_array[
"success"] = TRUE;
80 if(filesize($localdir . $cucode .
".csv") <= 0 and !isset($return_array[
"message"])){
81 $return_array[
"success"] == FALSE;
82 $return_array[
"error_message"] =
"CSV file not downloaded to file";