コード例 #1
0
function uploadFiles(&$drive_service, &$client, &$configObj, &$UsersAFSObj)
{
    foreach ($UsersAFSObj->fileList as $value) {
        $logline = date('Y-m-d H:i:s') . " File path: " . $value->path . "\n";
        fwrite($configObj->logFile, $logline);
        // Make sure the file still exists in AFS
        if (!file_exists($value->path)) {
            array_push($UsersAFSObj->failedFiles, $value->path);
            $logline = date('Y-m-d H:i:s') . " Upload failed.  File does not exist!" . "\n";
            fwrite($configObj->logFile, $logline);
            continue;
        }
        $parentFolderID = $UsersAFSObj->folderList[getParentFolder($value->path)];
        $logline = date('Y-m-d H:i:s') . " Parent folder name: " . $value->path . "\n";
        $logline = $logline . date('Y-m-d H:i:s') . " Parent folder ID: " . $parentFolderID . "\n";
        fwrite($configObj->logFile, $logline);
        // If it couldn't find the parent folder's ID, skip this file
        if ($parentFolderID == null) {
            $logline = date('Y-m-d H:i:s') . " Upload failed.  No parent ID for parent folder!" . "\n";
            fwrite($configObj->logFile, $logline);
            continue;
        }
        if ($client->isAccessTokenExpired()) {
            //Trade access token for refresh token
            if ($client->refreshToken($configObj->refreshToken) == null) {
                $logline = date('Y-m-d H:i:s') . ": Using refresh token, access token granted. \n";
                fwrite($configObj->logFile, $logline);
            } else {
                $logline = date('Y-m-d H:i:s') . ": Unable to obtain access token. \n";
                fwrite($configObj->logFile, $logline);
            }
        }
        //decides whether to do media or resumable upload and uploads file
        //1000 bytes is currently hardcoded as chunk size for resumable upload function
        //make a config file for the chunk size?
        $logline = date('Y-m-d H:i:s') . " Doing upload..." . "\n";
        fwrite($configObj->logFile, $logline);
        $results = doUpload($drive_service, $client, $value, $parentFolderID, $configObj);
        if ($results) {
            array_push($UsersAFSObj->failedFiles, $value->path);
            $logline = date('Y-m-d H:i:s') . " Failure" . "\n";
            fwrite($configObj->logFile, $logline);
        } else {
            ++$UsersAFSObj->numFilesUploaded;
            $logline = date('Y-m-d H:i:s') . " Success!" . "\n";
            fwrite($configObj->logFile, $logline);
        }
    }
}
コード例 #2
0
     continue;
 }
 if ($expireTime - time() < 100) {
     $newToken = generateToken($accessToken, $refreshToken, $expireTime, $clientID, $clientSecret, $stringArray);
     // If it failed the first time, try again
     if (!$newToken) {
         sleep(5);
         $newToken = generateToken($accessToken, $refreshToken, $expireTime, $clientID, $clientSecret, $stringArray);
     }
     // If it failed again, exit
     if (!$newToken) {
         include '../notification_email.php';
         exit;
     }
 }
 $parentFolderID = $folderList[getParentFolder($value->path)];
 // If it couldn't find the parent folder's ID, skip this file
 if ($parentFolderID == null) {
     continue;
 }
 $nextID = createFile(getFileName($value->path), $parentFolderID, $value->path, true, $accessToken, $stringArray);
 // If the API call returns an error, handle and retry it if possible
 if (is_array($nextID)) {
     array_push($stringArray, "Retrying this file...", "<br><br>");
     retryCall($nextID, getFileName($value->path), $parentFolderID, $value->path, true, $accessToken, $stringArray);
 }
 // Check to see if the file upload was successfull
 if (!is_array($nextID)) {
     $numFiles++;
     array_push($stringArray, "File '" . getFileName($value->path) . "' successfully uploaded", "<br>");
 } else {