public function deleteEschoolFromSystemEntirely()
 {
     // remove all mnet connections with any maharas
     if ($this->isCreated()) {
         foreach ($this->getMnetInstitutions() as $institution) {
             $institution->removeMnetConnection($this);
         }
     }
     GcrDatabaseAccessPostgres::deleteSchemaFromSystem($this);
     // delete moodledata directory for eschool
     exec(escapeshellcmd('rm -R ' . gcr::moodledataDir . $this->short_name . '/'));
     // delete global eschool row for this eschool and related address and person table rows
     GcrCommissionTable::getInstance()->createQuery('c')->delete()->where('c.eschool_id = ?', $this->short_name)->execute();
     GcrEclassroomTable::getInstance()->createQuery('e')->delete()->where('e.eschool_id = ?', $this->short_name)->execute();
     // delete password salt history for this eschool
     $q = Doctrine_Query::create()->delete('GcrEschoolSaltHistory')->where('eschoolid = ?', $this->id);
     $q->execute();
     if ($address = $this->getAddressObject()) {
         $address->delete();
     }
     if ($contact1 = $this->getPersonObject()) {
         $contact1->delete();
     }
     if ($contact2 = $this->getPerson2Object()) {
         $contact2->delete();
     }
     $this->delete();
 }
 public function executeDeleteEclassroom(sfWebRequest $request)
 {
     global $CFG;
     $CFG->current_app->requireLogin();
     if (!$CFG->current_app->hasPrivilege('GCUser')) {
         $CFG->current_app->gcError('Unauthorized access by user id ' . $CFG->current_app->getCurrentUser()->getObject()->id, 'gcpageaccessdenied');
     }
     $id = $request->getParameter('id');
     if (!$id) {
         $CFG->current_app->gcError('Missing Required parameter "id"', 'gcdatabaseerror');
     }
     $eclassroom = GcrEclassroomTable::getInstance()->find($id);
     if (!$eclassroom) {
         $CFG->current_app->gcError('eClassroom record not found', 'gcdatabaseerror');
     }
     $eclassroom->delete();
     $this->redirect($CFG->current_app->getUrl() . '/institution/eclassrooms');
 }
 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();
 }