Run it in console:
var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'html://path_to_script.js'; document.head.appendChild(script);
Run it in console:
var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'html://path_to_script.js'; document.head.appendChild(script);
Script to refresh all sections for all courses in Moodle system
$courses = get_courses(); foreach ($courses as $course){ course_create_sections_if_missing($course->id, [0,1,2,3,4,5,6,7,8,9,10,11,12]); rebuild_course_cache($course->id, true); }
Create directory /var/backups
mkdir /var/backups
crontab -e
Add Database backup to the cron file:
#Backup Database (Before each day starts, backup Moodle prod DB from MySQL/MariaDB) 4 4 * * * root mysqldump dbname -u user -ppsaaword | gzip > /var/backups/moodle-db-`date +\%Y-\%m-\%d-\%H-\%M-\%S`.sql.gz
Add moodledata backup to the cron file:
4 10 * * * zip -r /var/backups/moodledata-`date +\%Y-\%m-\%d-\%H-\%M-\%S`.zip /var/www/moodledata
Save 30 lasts backups
# Keep 30 SQL database backups and moodledata backups (last 30 backups of moodle) 2 2 * * * find /var/backups/* -mtime +10 -exec rm {} \;
How to upload custom file Moodle function
if(isset($_FILES['imageactivity']) && !empty($_FILES['imageactivity'])){ $file_url = $_FILES['imageactivity']['tmp_name']; $file_content = file_get_contents($file_url); $file_name = $_FILES['imageactivity']['name']; $fs = get_file_storage(); $draftitemid = file_get_unused_draft_itemid(); $contextid_local = 70; // Prepare file record object $fileinfo = array( 'contextid' => 165, // ID of context 165 'component' => 'user', // usually = table name 'filearea' => 'draft', // usually = table name 'itemid' => $draftitemid, // usually = ID of row in table 0 'filepath' => '/', // any path beginning and ending in / 'userid' => $USER->id, 'source' => $file_name, 'filename' => $file_name); // any filename // Create file containing content $fs->create_file_from_string($fileinfo, $file_content); file_prepare_draft_area($draftitemid, $contextid_local, 'local_metadata', 'image', 0); file_save_draft_area_files($draftitemid, $contextid_local, 'local_metadata', 'image', $draftitemid); }
Libreoffice service use CPU 100% on Server Moodle Ubuntu 16.04
Add to config.php file before include:
@error_reporting(E_ALL | E_STRICT); @ini_set('display_errors', '1'); $CFG->debug = (E_ALL | E_STRICT); $CFG->debugdisplay = 1;
After Updating files from MOODLE 3.1.5 to MOODLE 3.1.7 got this error:
Error code: codingerror !! !! Stack trace: * line 513
Continue reading Error code: codingerror !! !! Stack trace: * line 513
Disable php 7.0 in Apache
a2dismod php7.0
Continue reading How to change php 7.0 to php 5.6 Ubuntu 16.04
Download the installer:
sudo curl -s https://getcomposer.org/installer | php
Move the composer.phar
file:
sudo mv composer.phar /usr/local/bin/composer
Ubuntu PHP.INI 7.0 location:
/etc/php/7.0/apache2/php.ini
find and change
post_max_size=20M
upload_max_filesize=20M