Beispiel #1
0
 /**
  * @return void
  */
 public static function checkOrg()
 {
     try {
         if (!\PodioOrganization::get(self::$orgId)) {
             die('Not member of org.');
         }
     } catch (\PodioForbiddenError $e) {
         die('Not member of org.');
     }
 }
function do_backup($downloadFiles)
{
    global $config, $verbose;
    if ($verbose) {
        echo "Warning: This script may run for a LONG time\n";
    }
    $currentdir = getcwd();
    $timeStamp = date('Y-m-d_H-i');
    $backupTo = $config['backupTo'];
    $path_base = $backupTo . '/' . $timeStamp;
    mkdir($path_base);
    $podioOrgs = PodioOrganization::get_all();
    foreach ($podioOrgs as $org) {
        //org_id
        if ($verbose) {
            echo "Org: " . $org->name . "\n";
        }
        $path_org = $path_base . '/' . fixDirName($org->name);
        mkdir($path_org);
        $contactsFile = '';
        try {
            $contacts = PodioFetchAll::iterateApiCall('PodioContact::get_for_org', $org->org_id);
            $contactsFile .= contacts2text($contacts);
        } catch (PodioError $e) {
            show_error($e);
            $contactsFile .= "\n\nPodio Error:\n" . $e;
        }
        file_put_contents($path_org . '/' . 'podio_organization_contacts.txt', $contactsFile);
        foreach ($org->spaces as $space) {
            // space_id
            if ($verbose) {
                echo "Space: " . $space->name . "\n";
            }
            $path_space = $path_org . '/' . fixDirName($space->name);
            mkdir($path_space);
            $contactsFile = '';
            try {
                if ($space->name == "Employee Network") {
                    $filter = array('contact_type' => 'user');
                } else {
                    $filter = array('contact_type' => 'space');
                }
                $contacts = PodioFetchAll::iterateApiCall('PodioContact::get_for_space', $space->space_id, $filter);
                $contactsFile .= contacts2text($contacts);
            } catch (PodioError $e) {
                show_error($e);
                $contactsFile .= "\n\nPodio Error:\n" . $e;
            }
            file_put_contents($path_space . '/' . 'podio_space_contacts.txt', $contactsFile);
            $spaceApps = array();
            try {
                $spaceApps = PodioApp::get_for_space($space->space_id);
                RateLimitChecker::preventTimeOut();
            } catch (PodioError $e) {
                show_error($e);
            }
            foreach ($spaceApps as $app) {
                backup_app($app, $path_space, $downloadFiles);
            }
        }
    }
    if ($verbose) {
        show_success("Backup Completed successfully to " . $currentdir . "/" . $backupTo . "/" . $timeStamp);
    }
}