forked from moodle/moodle
/
edit_xml_file_save.class.php
100 lines (81 loc) · 3.76 KB
/
edit_xml_file_save.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
<?php // $Id$
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.com //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com //
// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
// //
// 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. //
// //
// This program 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: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
///////////////////////////////////////////////////////////////////////////
/// This class will save the changes performed to the comment of one file
class edit_xml_file_save extends XMLDBAction {
/**
* Init method, every subclass will have its own
*/
function init() {
parent::init();
/// Set own custom attributes
/// Get needed strings
$this->loadStrings(array(
/// 'key' => 'module',
));
}
/**
* Invoke method, every class will have its own
* returns true/false on completion, setting both
* errormsg and output as necessary
*/
function invoke() {
parent::invoke();
$result = true;
/// Set own core attributes
$this->does_generate = ACTION_NONE;
//$this->does_generate = ACTION_GENERATE_HTML;
/// These are always here
global $CFG, $XMLDB;
/// Do the job, setting result as needed
if (!data_submitted()) { ///Basic prevention
print_error('wrongcall', 'error');
}
/// Get parameters
$dirpath = required_param('dir', PARAM_PATH);
$dirpath = $CFG->dirroot . $dirpath;
$comment = required_param('comment', PARAM_CLEAN);
$comment = $comment;
/// Set comment and recalculate hash
$editeddir =& $XMLDB->editeddirs[$dirpath];
$structure =& $editeddir->xml_file->getStructure();
$structure->setComment($comment);
$structure->calculateHash(true);
/// If the hash has changed from the original one, change the version
/// and mark the structure as changed
$origdir =& $XMLDB->dbdirs[$dirpath];
$origstructure =& $origdir->xml_file->getStructure();
if ($structure->getHash() != $origstructure->getHash()) {
$structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
$structure->setChanged(true);
}
/// Launch postaction if exists (leave this here!)
if ($this->getPostAction() && $result) {
return $this->launch($this->getPostAction());
}
/// Return ok if arrived here
return $result;
}
}
?>