[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 3 // This file keeps track of upgrades to 4 // the data module 5 // 6 // Sometimes, changes between versions involve 7 // alterations to database structures and other 8 // major things that may break installations. 9 // 10 // The upgrade function in this file will attempt 11 // to perform all the necessary actions to upgrade 12 // your older installation to the current version. 13 // 14 // If there's something it cannot do itself, it 15 // will tell you what you need to do. 16 // 17 // The commands in here will all be database-neutral, 18 // using the methods of database_manager class 19 // 20 // Please do not forget to use upgrade_set_timeout() 21 // before any action that may take longer time to finish. 22 23 function xmldb_data_upgrade($oldversion) { 24 global $CFG, $DB, $OUTPUT; 25 26 $dbman = $DB->get_manager(); 27 28 29 // Moodle v2.2.0 release upgrade line 30 // Put any upgrade step following this 31 32 // Moodle v2.3.0 release upgrade line 33 // Put any upgrade step following this 34 35 if ($oldversion < 2012112901) { 36 // Check if there is a directory containing any old presets. 37 $olddatadir = $CFG->dataroot . '/data'; 38 $oldpresetdir = "$olddatadir/preset"; 39 if (file_exists($oldpresetdir)) { 40 // Get directory contents. 41 $userfolders = new DirectoryIterator($oldpresetdir); 42 // Store the system context, these are site wide presets. 43 $context = context_system::instance(); 44 // Create file storage object. 45 $fs = get_file_storage(); 46 // Create array of accepted files. 47 $arracceptedfilenames = array('singletemplate.html', 'listtemplateheader.html', 'listtemplate.html', 48 'listtemplatefooter.html', 'addtemplate.html', 'rsstemplate.html', 49 'rsstitletemplate.html', 'csstemplate.css', 'jstemplate.js', 50 'asearchtemplate.html', 'preset.xml'); 51 // Loop through all the folders, they should represent userids. 52 foreach ($userfolders as $userfolder) { 53 // If it is a file, skip it. 54 if ($userfolder->isFile()) { 55 continue; 56 } 57 // The folder name should represent the user id. 58 $userid = $userfolder->getFilename(); 59 // Skip if it is not numeric. 60 if (!is_numeric($userid)) { 61 continue; 62 } 63 // Skip if the number does not correspond to a user (does not matter if user was deleted). 64 if (!$DB->record_exists('user', array('id' => $userid))) { 65 continue; 66 } 67 // Open this folder. 68 $presetfolders = new DirectoryIterator("$oldpresetdir/$userid"); 69 foreach ($presetfolders as $presetfolder) { 70 // If it is a file, skip it. 71 if ($presetfolder->isFile()) { 72 continue; 73 } 74 // Save the name of the preset. 75 $presetname = $presetfolder->getFilename(); 76 // Get the files in this preset folder. 77 $presetfiles = new DirectoryIterator("$oldpresetdir/$userid/$presetname"); 78 // Now we want to get the contents of the presets. 79 foreach ($presetfiles as $file) { 80 // If it is not a file, skip it. 81 if (!$file->isFile()) { 82 continue; 83 } 84 // Set the filename. 85 $filename = $file->getFilename(); 86 // If it is not in the array of accepted file names skip it. 87 if (!in_array($filename, $arracceptedfilenames)) { 88 continue; 89 } 90 // Store the full file path. 91 $fullfilepath = "$oldpresetdir/$userid/$presetname/$filename"; 92 // Create file record. 93 $filerecord = array('contextid' => $context->id, 94 'component' => 'mod_data', 95 'filearea' => 'site_presets', 96 'itemid' => 0, 97 'filename' => $filename, 98 'userid' => $userid); 99 // Check to ensure it does not already exists in the file directory. 100 if (!$fs->file_exists($context->id, 'mod_data', 'site_presets', 0, '/' . $presetfolder . '/', $filename)) { 101 $filerecord['filepath'] = '/' . $presetfolder . '/'; 102 } else { 103 $filerecord['filepath'] = '/' . $presetfolder . '_' . $userid . '_old/'; 104 } 105 $fs->create_file_from_pathname($filerecord, $fullfilepath); 106 // Remove the file. 107 @unlink($fullfilepath); 108 } 109 // Remove the preset directory. 110 @rmdir("$oldpresetdir/$userid/$presetname"); 111 } 112 // Remove the user directory. 113 @rmdir("$oldpresetdir/$userid"); 114 } 115 // Remove the final directories. 116 @rmdir("$oldpresetdir"); 117 @rmdir("$olddatadir"); 118 } 119 120 upgrade_mod_savepoint(true, 2012112901, 'data'); 121 } 122 123 // Moodle v2.4.0 release upgrade line 124 // Put any upgrade step following this 125 126 127 // Moodle v2.5.0 release upgrade line. 128 // Put any upgrade step following this. 129 130 131 // Moodle v2.6.0 release upgrade line. 132 // Put any upgrade step following this. 133 134 // Moodle v2.7.0 release upgrade line. 135 // Put any upgrade step following this. 136 137 // Moodle v2.8.0 release upgrade line. 138 // Put any upgrade step following this. 139 140 return true; 141 } 142 143
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |