Skip to content

Commit

Permalink
2017082900 release candidate (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalmsten-panopto authored Aug 29, 2017
1 parent 05b87f6 commit fc00037
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 55 deletions.
63 changes: 62 additions & 1 deletion classes/rollingsync.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,68 @@ public static function courserestored(\core\event\course_restored $event) {
$originalcourseid = intval($event->other['originalcourseid']);

$panoptodata = new panopto_data($newcourseid);
$panoptodata->init_and_sync_import($originalcourseid);
$originalpanoptodata = new panopto_data($originalcourseid);

// We should only perform the import if both the target and the source course are provisioned in panopto
if (isset($panoptodata->servername) && !empty($panoptodata->servername) &&
isset($panoptodata->applicationkey) && !empty($panoptodata->applicationkey) &&
isset($panoptodata->sessiongroupid) && !empty($panoptodata->sessiongroupid) &&
isset($originalpanoptodata->servername) && !empty($originalpanoptodata->servername) &&
isset($originalpanoptodata->applicationkey) && !empty($originalpanoptodata->applicationkey) &&
isset($originalpanoptodata->sessiongroupid) && !empty($originalpanoptodata->sessiongroupid)) {

$panoptodata->init_and_sync_import($originalcourseid);
}
}
}

/**
* Called when a user has been unenrolled.
*
* @param \core\event\user_enrolment_deleted $event
*/
public static function userenrolmentdeleted(\core\event\user_enrolment_deleted $event) {
if (!\panopto_data::is_main_block_configured() ||
!\panopto_data::has_minimum_version()) {
return;
}

$task = new \block_panopto\task\sync_user();
$task->set_custom_data(array(
'courseid' => $event->courseid,
'userid' => $event->relateduserid
));

if (get_config('block_panopto', 'async_tasks')) {
\core\task\manager::queue_adhoc_task($task);
} else {
$task->execute();
}
}

/**
* Called when a user has been enrolled.
*
* @param \core\event\user_enrolment_created $event
*/
public static function userenrolmentcreated(\core\event\user_enrolment_created $event) {
if (!\panopto_data::is_main_block_configured() ||
!\panopto_data::has_minimum_version()) {
return;
}

if (get_config('block_panopto', 'sync_on_enrolment')) {
$task = new \block_panopto\task\sync_user();
$task->set_custom_data(array(
'courseid' => $event->courseid,
'userid' => $event->relateduserid
));

if (get_config('block_panopto', 'async_tasks')) {
\core\task\manager::queue_adhoc_task($task);
} else {
$task->execute();
}
}
}
}
51 changes: 51 additions & 0 deletions classes/task/sync_user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* the sync user class for Panopto, syncs user permissions with Panopto server, called on unenrollment event
*
* @package block_panopto
* @copyright Panopto 2009 - 2016
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_panopto\task;
defined('MOODLE_INTERNAL') || die();
require_once(dirname(__FILE__) . '/../../lib/panopto_data.php');
/**
* Panopto "sync user" task.
* @copyright Panopto 2009 - 2016 /With contributions
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class sync_user extends \core\task\adhoc_task {
/**
* the the parent component for this class
*/
public function get_component() {
return 'block_panopto';
}
/**
* the main execution function of the class
*/
public function execute() {
global $DB;
$eventdata = (array) $this->get_custom_data();
$coursepanopto = new \panopto_data($eventdata['courseid']);

if (isset($coursepanopto->servername) && !empty($coursepanopto->servername) &&
isset($coursepanopto->applicationkey) && !empty($coursepanopto->applicationkey)) {
$coursepanopto->sync_external_user($eventdata['userid']);
}
}
}
11 changes: 10 additions & 1 deletion db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
defined('MOODLE_INTERNAL') || die();

$observers = array(
// User enrolled event.
array(
'eventname' => '\core\event\course_created',
'callback' => 'block_panopto_rollingsync::coursecreated',
Expand All @@ -39,4 +38,14 @@
'eventname' => '\core\event\course_deleted',
'callback' => 'block_panopto_rollingsync::coursedeleted',
),
// User unenroled event.
array(
'eventname' => '\core\event\user_enrolment_deleted',
'callback' => 'block_panopto_rollingsync::userenrolmentdeleted',
),
// User enroled event.
array(
'eventname' => '\core\event\user_enrolment_created',
'callback' => 'block_panopto_rollingsync::userenrolmentcreated',
)
);
46 changes: 31 additions & 15 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
*/
function update_upgrade_progress($currentprogress, $totalitems, $progressstep = null) {
if (isset($progressstep) && !empty($progressstep)) {
error_log('Now beginning the step: ' . $progressstep);
panopto_data::print_log('Now beginning the step: ' . $progressstep);
}

if ($currentprogress > 0) {
error_log('Processing folder ' . $currentprogress . ' out of ' . $totalitems);
panopto_data::print_log('Processing folder ' . $currentprogress . ' out of ' . $totalitems);
}
}

Expand Down Expand Up @@ -332,7 +332,7 @@ function xmldb_block_panopto_upgrade($oldversion = 0) {
}
} else {
// Shouldn't hit this case, but in the case a row in the DB has invalid data move it to the old_foldermap.
error_log(get_string('removing_invalid_folder_row', 'block_panopto'));
panopto_data::print_log(get_string('removing_corrupt_folder_row', 'block_panopto') . $oldcourse->moodleid);
panopto_data::delete_panopto_relation($oldcourse->moodleid, true);
// Continue to the next entry assuming this one was cleanup.
continue;
Expand All @@ -355,20 +355,35 @@ function xmldb_block_panopto_upgrade($oldversion = 0) {

// Imports SHOULD still work for this case, so continue to below code.
}
$oldpanoptocourse->courseimports = panopto_data::get_import_list($oldpanoptocourse->panopto->moodlecourseid);
foreach ($oldpanoptocourse->courseimports as $courseimport) {
$courseimports = panopto_data::get_import_list($oldpanoptocourse->panopto->moodlecourseid);
foreach ($courseimports as $courseimport) {
$importpanopto = new panopto_data($courseimport);

// False means the user failed to get the folder.
$importpanoptofolder = $importpanopto->get_folders_by_id();
if (isset($importpanoptofolder) && $importpanoptofolder === false) {
$usercanupgrade = false;
break;
} else if (!isset($importpanoptofolder) || $importpanoptofolder === -1) {
// In this case the folder was not found, not an access issue. Most likely the folder was deleted and this is an old entry.
// Move the entry to the old_foldermap so user still has a reference.

$existingmoodlecourse = $DB->get_record('course', array('id' => $courseimport));

$moodlecourseexists = isset($existingmoodlecourse) && $existingmoodlecourse !== false;
$hasvalidpanoptodata = isset($importpanopto->servername) && !empty($importpanopto->servername) &&
isset($importpanopto->applicationkey) && !empty($importpanopto->applicationkey);

// Only perform the actions below if the import is in a valid state, otherwise remove it.
if ($moodlecourseexists && $hasvalidpanoptodata) {
// False means the user failed to get the folder.
$importpanoptofolder = $importpanopto->get_folders_by_id();
if (isset($importpanoptofolder) && $importpanoptofolder === false) {
$usercanupgrade = false;
break;
} else if (!isset($importpanoptofolder) || $importpanoptofolder === -1) {
// In this case the folder was not found, not an access issue. Most likely the folder was deleted and this is an old entry.
// Move the entry to the old_foldermap so user still has a reference.
panopto_data::delete_panopto_relation($courseimport, true);
// We can still continue on with the upgrade, assume this was an old entry that was deleted from Panopto side.
}
} else {
panopto_data::print_log(get_string('removing_corrupt_folder_row', 'block_panopto') . $courseimport);
panopto_data::delete_panopto_relation($courseimport, true);
// We can still continue on with the upgrade, assume this was an old entry that was deleted from Panopto side.
// Continue to the next entry assuming this one was cleanup.
continue;
}
}
}
Expand All @@ -391,7 +406,8 @@ function xmldb_block_panopto_upgrade($oldversion = 0) {
foreach ($panoptocourseobjects as $mappablecourse) {
// This should add the required groups to the existing Panopto folder.
$mappablecourse->panopto->provision_course($mappablecourse->provisioninginfo);
foreach ($mappablecourse->courseimports as $importedcourse) {
$courseimports = panopto_data::get_import_list($mappablecourse->panopto->moodlecourseid);
foreach ($courseimports as $importedcourse) {
$mappablecourse->panopto->init_and_sync_import($importedcourse);
}

Expand Down
14 changes: 12 additions & 2 deletions lang/en/block_panopto.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,18 @@
$string['block_global_add_courses'] = 'Add Moodle courses to Panopto';
$string['block_global_application_key'] = 'Application Key';
$string['block_global_application_key_desc'] = 'Enter the Application Key from the Panopto Identity Providers page.';
$string['block_panopto_check_server_status'] = 'Check server health before loading block.';
$string['block_panopto_check_server_status_desc'] = 'This checks if the target Panopto server is up at the beginning to avoid possible long timeout calls when the server is unreachable. This is set to false by default because it uses platform / OS dependent feature. It should be set to true only when Panopto support recommends it.';
$string['block_panopto_publisher_system_role_mapping'] = 'System roles with provisioning permissions';
$string['block_panopto_publisher_system_role_mapping_desc'] = 'Select which system roles can provision new Panopto course folders.';
$string['block_panopto_publisher_mapping'] = 'Publisher role mapping';
$string['block_panopto_publisher_mapping_desc'] = 'Select which course roles are set as publishers in new Panopto course folders.';
$string['block_panopto_sync_after_provisioning'] = 'Sync enroled users after successfully provisioning';
$string['block_panopto_sync_after_provisioning_desc'] = 'Syncs all users enroled in a course after it has been provisioned. Turn on this option only if you have a problem with the default behavior which syncs a user\'s permission when each user accesses this block in one of the enrolled courses.';
$string['block_panopto_sync_on_enrolment'] = 'Sync users after class enrolment';
$string['block_panopto_sync_on_enrolment_desc'] = 'This feature will fire a sync operation on a student any time they are enroled into a course with a valid Panopto folder. Turn on this option only if you have a problem with the default behavior which syncs a user\'s permission when each user accesses this block in one of the enrolled courses.';
$string['block_panopto_print_log_to_file'] = 'Redirect error logs to text file';
$string['block_panopto_print_log_to_file_desc'] = 'This option will redirect any panopto logging from the PHP error_log to a PanoptoLogs.txt file inside the base moodle directory. It should only be set to true when Panopto support recommends it.';
$string['block_panopto_creator_mapping'] = 'Creator role mapping';
$string['block_panopto_creator_mapping_desc'] = 'Select which course roles are set as creators in new Panopto course folders.';
$string['block_panopto_non_editing_teacher_provision'] = 'Allow non-editing teacher to provision';
Expand All @@ -55,6 +63,8 @@
$string['block_panopto_server_number_name'] = 'Number of Panopto Servers';
$string['block_panopto_auto_provision'] = 'Automatically provision newly created courses';
$string['block_panopto_auto_provision_desc'] = 'Enable this option to automatically provision a Panopto course folder when a course is created.';
$string['block_panopto_async_tasks'] = 'Asynchronous sync tasks';
$string['block_panopto_async_tasks_desc'] = 'Enable this option to allow the enrolment, unenrolment, and delete user tasks to happen asynchronously (may have a short delay before running)';
$string['block_panopto_prefix_new_folder_shortnames'] = 'Prefix new Panopto folder display names with the Moodle course\'s shortname.';
$string['block_panopto_prefix_new_folder_shortnames_desc'] = 'Enable this option to add the provisioned course shortname to the beginning of newly made Panopto folder\'s display name.';
$string['completed_recordings'] = 'Completed Recordings';
Expand Down Expand Up @@ -83,7 +93,7 @@
$string['no_server'] = 'There are no servers set up for provisioning. Please contact system administrator.';
$string['no_students'] = 'No students.';
$string['no_users_synced'] = 'No Users synced with folder yet';
$string['no_users_synced_desc'] = 'With new API all users enrolled in this course will be synced with Panopto when they login to Moodle.';
$string['no_users_synced_desc'] = 'With new API all users enroled in this course will be synced with Panopto when they attempt to access a Panopto block through Moodle.';
$string['or'] = 'OR';
$string['panopto_server_error'] = 'Panopto server {$a} returned with server error, will try again on next sign in.';
$string['panopto:addinstance'] = 'Add a new Panopto block';
Expand All @@ -107,7 +117,7 @@
$string['publisher'] = 'Publisher';
$string['publisher_help'] = 'A Publisher can approve content submitted by Creators';
$string['publishers'] = 'Publishers';
$string['removing_invalid_folder_row'] = "Moodle course was deleted from Moodle or the link to Panopto does not contain all of the necessary info to connect to this folder. Moving foldermap entry to old_foldermap for user reference.\n";
$string['removing_corrupt_folder_row'] = "Foldermap entry appears corrupted, moving entry to old_foldermap for user reference. Corrupted row used for course with Moodle Id: ";
$string['reprovision_course_link_text'] = 'Reprovision Course';
$string['result'] = 'Result';
$string['require_panopto_version_title'] = 'Minimum Panopto version required for this version of the Moodle Panopto block';
Expand Down
5 changes: 3 additions & 2 deletions lib/panopto_auth_soap_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__) . '/AuthManagement/AuthManagementAutoload.php');
require_once(dirname(__FILE__) . '/panopto_data.php');

class panopto_auth_soap_client extends SoapClient {

Expand Down Expand Up @@ -73,7 +74,7 @@ public function get_server_version() {
if ($authmanagementserviceget->GetServerVersion()) {
$returnvalue = $authmanagementserviceget->getResult()->GetServerVersionResult;
} else {
error_log(print_r($authmanagementserviceget->getLastError(), true));
panopto_data::print_log(print_r($authmanagementserviceget->getLastError(), true));
}
return $returnvalue;
}
Expand All @@ -99,7 +100,7 @@ public function report_integration_info($idprovidername, $moduleversion, $target
$returnvalue = true;
} else {
$lasterror = $authmanagementservicereport->getLastError()['AuthManagementServiceReport::ReportIntegrationInfo'];
error_log(print_r($lasterror, true));
panopto_data::print_log(print_r($lasterror, true));
}

return $returnvalue;
Expand Down
Loading

0 comments on commit fc00037

Please sign in to comment.