forked from data-quest/Lizenzstatus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewYear2017Cronjob.class.php
106 lines (85 loc) · 3 KB
/
NewYear2017Cronjob.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/*
* This file is part of the Lizenzstatus plugin.
*
* Copyright (c) 2016 data-quest <info@data-quest.de>
*
* This program 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 2 of
* the License, or (at your option) any later version.
*/
require_once 'lib/classes/CronJob.class.php';
class NewYear2017Cronjob extends CronJob
{
/**
* @return string The name of the cronjob.
*/
public static function getName()
{
return _('Lizenzstatus');
}
/**
* @return string The description of the cronjob.
*/
public static function getDescription()
{
return _('Ändert den Download-Status bestimmter Lizenzen zum 1.1.2017, um den neuen Anforderungen der VG Wort gerecht zu werden.');
}
/**
* Setup method that loads all required classes and stuff.
*
* @throws Exception Throws an exception if something went wrong.
*/
public function setUp()
{
global $STUDIP_BASE_PATH;
require_once($STUDIP_BASE_PATH . '/lib/classes/Config.class.php');
require_once($STUDIP_BASE_PATH . '/config/config_local.inc.php');
}
/**
* @return Array The parameters for this cronjob.
*/
public static function getParameters()
{
return array();
}
/**
* Executes the cronjob.
*/
public function execute($last_result, $parameters = array())
{
//get db connection:
$db = DBManager::get();
$license_changes = Config::Get()->DOCUMENT_LICENSE_CHANGES_2017;
if(!is_array($license_changes)) {
//Configuration parameter wasn't set in config_local.inc.php:
//Use default settings:
$license_changes = array(
'7' => '3' //Documents with License-ID 7 can't be downloaded anymore (protected = 3)
);
}
//execute queries:
$statement = $db->prepare(
"UPDATE document_licenses set protected = :protection_state
WHERE license_id = :license_id"
);
foreach($license_changes as $license_id => $protection_state) {
echo 'Updating license with ID ' . $license_id . "...\n";
$result = $statement->execute(
array(
'protection_state' => $protection_state,
'license_id' => $license_id
)
);
if($result === false) {
//error while updating:
echo 'ERROR while updating license-ID ' . $license_id . ' to protection state ' . $protection_state . "!\n";
} else {
echo 'Updated license-ID ' . $license_id . ' to protection state ' . $protection_state . "!\n";
}
}
//close db connection:
$db = null;
}
}