protected function process_mediaelementjs($data) { global $CFG, $DB; $data = (object) $data; $oldid = $data->id; $data->course = $this->get_courseid(); $data = GcrStorageAccessS3::refreshUrl($data); // insert the url record $newitemid = $DB->insert_record('mediaelementjs', $data); // immediately after inserting "activity" record, call this $this->apply_activity_instance($newitemid); }
public static function refreshUrl($mdl_mediaelementjs) { $url = $mdl_mediaelementjs->externalurl; if (strpos($url, 'institution/getUserStorageFile?')) { $file_param = self::FILE_GET_PARAMETER . '='; $str_start = strpos($url, $file_param); if ($str_start) { $short_name = GcrEschoolTable::parseShortNameFromUrl($url); $app = GcrInstitutionTable::getApp($short_name); $institution = $app->getInstitution(); $short_name = $institution->getShortName(); $str_start += strlen($file_param); $str_end = strpos($url, '&', $str_start); $filename = substr($url, $str_start, $str_end - $str_start); $filename = urldecode($filename); $str_start = strpos($url, '&app='); if ($str_start) { $str_start += strlen('&app='); $str_end = strpos($url, '&', $str_start); $short_name_user_app = substr($url, $str_start, $str_end - $str_start); $user_app = GcrInstitutionTable::getApp($short_name_user_app); if ($user_app) { $short_name = $short_name_user_app; } } $params = array(self::FILE_GET_PARAMETER => $filename, 'course_id' => $mdl_mediaelementjs->course, 'app' => $short_name); $mdl_mediaelementjs->externalurl = GcrStorageAccessS3::generateStaticUrl($filename, $params, $app); } } return $mdl_mediaelementjs; }
public function executeGetUserStorageFile(sfWebRequest $request) { global $CFG; $get_params = $request->getGetParameters(); $signed_request = new GcrSignedRequest($get_params); if (!$signed_request->validateSignature()) { $CFG->current_app->gcError('Signature Invalid', 'gcpageaccessdenied'); } $file = $get_params[GcrStorageAccessS3::FILE_GET_PARAMETER]; if ($file) { if (!isset($get_params['app'])) { $app = $CFG->current_app->getInstitution(); } else { $app = GcrInstitutionTable::getApp($get_params['app']); } $s3_storage = new GcrStorageAccessS3($app); if (!$s3_storage->isPublicObject($file)) { $CFG->current_app->requireLogin(); $current_user = $CFG->current_app->getCurrentUser(); $role_manager = $current_user->getRoleManager(); if (isset($get_params['course_id']) && !$role_manager->hasPrivilege('EschoolAdmin')) { // make sure the current user has access to this course $flag = false; $mdl_course = $CFG->current_app->getCourse($get_params['course_id']); if ($mdl_course) { // For new course instances, we want to maintain access to // Cloud Storage URLs with course id signed to parent course. $course_collection = $mdl_course->getCourseCollection(); if ($course_collection) { foreach ($course_collection->getCourses() as $course_instance) { if ($role_manager->hasCourseAccess($course_instance)) { $flag = true; break; } } } else { $flag = $role_manager->hasCourseAccess($mdl_course); } } else { $CFG->current_app->gcError('course_id parameter ' . $get_params['course_id'] . 'does not exist', 'gcdatabaseerror'); } if (!$flag) { $CFG->current_app->gcError('User Does Not Have Course Access', 'gcpageaccessdenied'); } } } $url = $s3_storage->getObjectUrl($file); } else { $url = $CFG->current_app->getUrl(); } $this->redirect($url); }
public function deleteObject($obj) { if ($this->authorizeWriteAccess($obj)) { parent::deleteObject($obj); } else { $this->app->gcError('User does not have permission to access AWS S3 resource: ' . $obj, 'gcdatabaseerror'); } }
public function refreshMdlMediaelementjsUrls() { $this->start_time = time(); $count = 0; $this->operation_description = 'Refresh Cloud Storage Video Urls:'; foreach ($this->app_array as $eschool) { $ts = time(); $mdl_mediaelementjs_records = $eschool->selectFromMdlTable('mediaelementjs'); foreach ($mdl_mediaelementjs_records as $mdl_mediaelementjs) { $old_url = $mdl_mediaelementjs->externalurl; $mdl_mediaelementjs = GcrStorageAccessS3::refreshUrl($mdl_mediaelementjs, $eschool->getInstitution()); if ($old_url != $mdl_mediaelementjs->externalurl) { $eschool->updateMdlTable('mediaelementjs', array('externalurl' => $mdl_mediaelementjs->externalurl), array('id' => $mdl_mediaelementjs->id)); $count++; } } $seconds = time() - $ts; $this->updateLogFile($eschool, true, $seconds); } $this->close(); return $count; }