Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Bug 1928270: Be able to unlock locked collections
Browse files Browse the repository at this point in the history
- also fixing install code error

Change-Id: If447aa18cc1b3bdf056ecec3a8e1ed3a04a0238e
Signed-off-by: Robert Lyon <robertl@catalyst.net.nz>
  • Loading branch information
robertlyon777 committed May 17, 2021
1 parent 291297f commit 127de8f
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 3 deletions.
2 changes: 2 additions & 0 deletions htdocs/lang/en.utf8/collection.php
Expand Up @@ -215,3 +215,5 @@
$string['verificationtobedone'] = 'Confirm statement for the portfolio "%s" by %s';
$string['verificationdone'] = 'Confirmed statement for the portfolio "%s" by %s';
$string['removeaccess'] = 'Remove my access from the portfolio "%s" by %s';

$string['lockedcollection'] = 'Locked until %s';
23 changes: 23 additions & 0 deletions htdocs/lib/collection.php
Expand Up @@ -2229,6 +2229,9 @@ public function lock_collection() {
WHERE collection = ?
)";
execute_sql($sql, array($collectionid));
// Set the rollover / unlock date
// TODO - get this to be an institution / block setting rather than hard code for 6 months
execute_sql("UPDATE {collection_template} SET rolloverdate = ? WHERE collection = ?", array(db_format_timestamp(time()), $collectionid));
}

/**
Expand Down Expand Up @@ -2318,3 +2321,23 @@ function get_active_collection_template($institution='mahara') {
return false;
}

/**
* Unlock the collections by the rollover date
*
* When unlocking via rollover we leave the views still locked
* so a person can only delete their collection but not edit it
*
* @param $date string A valid date or string that can be used by strtotime() function
*
*/
function unlock_collections_by_rollover($date = '-6 months') {
// Unlock the collections
$rollover = db_format_timestamp(strtotime($date));
execute_sql("UPDATE {collection} SET lock = 0
WHERE id IN (
SELECT ct.collection FROM {collection_template} ct
JOIN {collection} c ON c.id = ct.collection
WHERE ct.rolloverdate < ?
AND c.lock = 1
)", array($rollover));
}
1 change: 1 addition & 0 deletions htdocs/lib/cron.php
Expand Up @@ -21,6 +21,7 @@
require_once(get_config('docroot') . 'lib/activity.php');
require_once(get_config('docroot') . 'lib/file.php');
require_once(get_config('docroot') . 'webservice/lib.php');
require_once(get_config('docroot') . 'lib/collection.php');
if (file_exists(get_config('docroot') . 'local/lib/cron.php')) {
require_once(get_config('docroot') . 'local/lib/cron.php');
}
Expand Down
5 changes: 3 additions & 2 deletions htdocs/lib/db/install.xml
Expand Up @@ -1073,6 +1073,7 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="collection" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="originaltemplate" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="rolloverdate" TYPE="datetime" NOTNULL="false" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
Expand Down Expand Up @@ -1526,8 +1527,8 @@
<TABLE NAME="view_copy_queue">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="collection" TYPE="int" LENGTH="10" />
<FIELD NAME="view" TYPE="int" LENGTH="10" />
<FIELD NAME="collection" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="usr" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
<FIELD NAME="status" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" />
Expand Down
21 changes: 21 additions & 0 deletions htdocs/lib/db/upgrade.php
Expand Up @@ -2233,5 +2233,26 @@ function xmldb_core_upgrade($oldversion=0) {
}
}

if ($oldversion < 2021051300) {
log_debug('Add column to the "collection_template" table to track unlock / rollover date');
$table = new XMLDBTable('collection_template');
$field = new XMLDBField('rolloverdate');
if (!field_exists($table, $field)) {
$field->setAttributes(XMLDB_TYPE_DATETIME, null, null);
add_field($table, $field);
}
if (!get_record('cron', 'callfunction', 'collection_rollover')) {
log_debug('Add cron job for unlocking collections by rollover date');
$cron = new stdClass();
$cron->callfunction = 'unlock_collections_by_rollover';
$cron->minute = '0';
$cron->hour = '3';
$cron->day = '*';
$cron->month = '*';
$cron->dayofweek = '*';
insert_record('cron', $cron);
}
}

return $status;
}
1 change: 1 addition & 0 deletions htdocs/lib/upgrade.php
Expand Up @@ -1054,6 +1054,7 @@ function core_install_firstcoredata_defaults() {
'cron_email_reset_rebounce' => array(rand(0, 59), rand(0, 23), '*', '*', '*'),
'auth_clean_expired_migrations' => array('0', '2,14', '*', '*', '*'),
'portfolio_auto_copy' => array('*', '*', '*', '*', '*'),
'collection_rollover' => array('0', '3', '*', '*', '*'),
);
foreach ($cronjobs as $callfunction => $times) {
$cron = new stdClass();
Expand Down
2 changes: 1 addition & 1 deletion htdocs/lib/version.php
Expand Up @@ -16,7 +16,7 @@
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.

$config->version = 2021042700;
$config->version = 2021051300;
$config->series = '21.10';
$config->release = '21.10dev';
$config->minupgradefrom = 2017031605;
Expand Down
5 changes: 5 additions & 0 deletions htdocs/lib/view.php
Expand Up @@ -5921,6 +5921,11 @@ public static function get_extra_collection_info(&$collectiondata, $gettags=true
$c->sharedby = $institutions[$c->institution]->displayname;
}

if (isset($c->lockedcoll) && $c->lockedcoll) {
$unlockdate = get_field('collection_template', 'rolloverdate', 'collection', $c->{$useid});
$c->unlockcoll = !empty($unlockdate) ? format_date(strtotime($unlockdate)) : null;
}

$c = (array)$c;

// Now that we have the owner & group records, create a temporary Collection object
Expand Down
3 changes: 3 additions & 0 deletions htdocs/theme/raw/templates/view/indexresults.tpl
Expand Up @@ -168,6 +168,9 @@
<br>
{str tag=modified section=mahara} {format_date(strtotime($view.vmtime), 'strftimerecentyear')}
<br>
{if $view.lockedcoll && $view.unlockcoll}{str tag=lockedcollection section=collection arg1=$view.unlockcoll}
<br>
{/if}
</li>
{if $view.submittedto}
<li class="view-details dropdown-item">
Expand Down

0 comments on commit 127de8f

Please sign in to comment.