public static function deleteBucket($app)
 {
     $user_storage_s3 = Doctrine::getTable('GcrUserStorageS3')->findOneByAppId($app->getShortName());
     if ($user_storage_s3) {
         $account = GcrUserStorageS3Table::getAccount($app);
         define('AWS_KEY', $account->getAccessKeyId());
         define('AWS_SECRET_KEY', $account->getSecretAccessKey());
         gcr::loadSdk('aws');
         $api = new AmazonS3();
         $api->delete_bucket($user_storage_s3->getBucketName(), true);
         $user_storage_s3->delete();
     }
 }
 public static function mimeinfo($filename)
 {
     $mimeinfo = self::getMimetypesArray();
     $s3_url = GcrUserStorageS3Table::parseS3Url($filename);
     if ($s3_url) {
         $filename = $s3_url;
     }
     if (preg_match('/\\.([a-z0-9]+)$/i', $filename, $match)) {
         if (isset($mimeinfo[strtolower($match[1])]['type'])) {
             return $mimeinfo[strtolower($match[1])]['type'];
         }
     }
     return false;
 }
Exemple #3
0
 /**
  * Constructor
  * @param int $repositoryid
  * @param object $context
  * @param array $options
  */
 public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array())
 {
     parent::__construct($repositoryid, $context, $options);
     // OVERWRITE 1: replacement
     // changed from
     // $this->access_key = get_config('s3', 'access_key');
     // $this->secret_key = get_config('s3', 'secret_key');
     // To:
     global $CFG;
     $account = GcrUserStorageS3Table::getAccount($CFG->current_app->getInstitution());
     $this->access_key = $account->getAccessKeyId();
     $this->secret_key = $account->getSecretAccessKey();
     // END OVERWRITE 1
     $this->s = new S3($this->access_key, $this->secret_key);
     $this->s->setExceptions(true);
 }
 public function __construct($app = false)
 {
     $this->app = $app;
     if (!$app) {
         global $CFG;
         $this->app = $CFG->current_app;
     }
     $account = GcrUserStorageS3Table::getAccount($this->app);
     define('AWS_KEY', $account->getAccessKeyId());
     define('AWS_SECRET_KEY', $account->getSecretAccessKey());
     gcr::loadSdk('aws');
     $this->api = new AmazonS3();
     if (!($user_storage_s3 = Doctrine::getTable('GcrUserStorageS3')->findOneByAppId($this->app->getInstitution()->getShortName()))) {
         $user_storage_s3 = $this->createBucket($account);
     } else {
         $this->bucket = $user_storage_s3->getBucketName();
     }
 }
 public function deleteInstitutionFromSystemEntirely()
 {
     // delete each moodle instance owned by this institution
     foreach ($this->getEschools() as $eschool) {
         $eschool->deleteEschoolFromSystemEntirely();
     }
     // delete this institution's database schema
     GcrDatabaseAccessPostgres::deleteSchemaFromSystem($this);
     // delete moodledata directory for institution
     exec(escapeshellcmd('rm -R ' . gcr::moodledataDir . $this->short_name . '/'));
     // delete password salt history for this institution
     Doctrine_Query::create()->delete('GcrInstitutionSaltHistory')->where('institutionid = ?', $this->id)->execute();
     Doctrine_Query::create()->delete('GcrTrial t')->where('t.organization_id = ?', $this->id)->execute();
     GcrChainedPaymentTable::getInstance()->createQuery('c')->delete()->where('c.user_institution_id = ?', $this->short_name)->execute();
     GcrChatSessionTable::getInstance()->createQuery('c')->delete()->where('c.eschool_id = ?', $this->short_name)->execute();
     GcrChatSessionUsersTable::getInstance()->createQuery('c')->delete()->where('c.user_eschool_id = ?', $this->short_name)->execute();
     GcrChatSessionInviteTable::getInstance()->createQuery('c')->delete()->where('c.user_eschool_id = ?', $this->short_name)->orWhere('c.from_user_eschool_id = ?', $this->short_name)->execute();
     GcrCommissionTable::getInstance()->createQuery('c')->delete()->where('c.institution_id = ?', $this->short_name)->execute();
     GcrEclassroomTable::getInstance()->createQuery('e')->delete()->where('e.user_institution_id = ?', $this->short_name)->execute();
     GcrEschoolMonthlyDataTable::getInstance()->createQuery('e')->delete()->where('e.eschool_id = ?', $this->short_name)->execute();
     GcrUserMonthlyDataTable::getInstance()->createQuery('u')->delete()->where('u.user_institution_id = ?', $this->short_name)->execute();
     GcrPayoffTable::getInstance()->createQuery('p')->delete()->where('p.user_eschool_id = ?', $this->short_name)->execute();
     GcrPurchaseTable::deleteInstitutionRecords($this);
     GcrUserStorageS3Table::deleteBucket($this);
     if ($address = $this->getAddressObject()) {
         $address->delete();
     }
     if ($contact1 = $this->getPersonObject()) {
         $contact1->delete();
     }
     if ($contact2 = $this->getPerson2Object()) {
         $contact2->delete();
     }
     $this->delete();
 }