Tuesday, December 17, 2013

Moodle how to bypass sso default login

To bypass a sso default login and just want to use the manual user login, you type

http://domainurl/auth/absso/login.php?bypass_sso=TRUE

Monday, September 16, 2013

Reset identity on a column of table

To reset the identity value of a table

DBCC CHECKIDENT ('database.tablename', RESEED, 0);

How to view table size

SELECT
    t.NAME AS TableName,
    p.rows AS RowCounts,
    SUM(a.total_pages) * 8 AS TotalSpaceKB,
    SUM(a.used_pages) * 8 AS UsedSpaceKB,
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM
    sys.tables t
INNER JOIN     
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN
    sys.allocation_units a ON p.partition_id = a.container_id
WHERE
    t.NAME NOT LIKE 'dt%'
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255
GROUP BY
    t.Name, p.Rows
ORDER BY
    t.Name

Monday, August 19, 2013

Error while installing bb collaborate

When trying to install bbcollaborate, the error is

"An error occurred communicating with the SAS server. Please contact your administrator."

This is happening because there are orphaned recording that has no audio as shown in this FAQ

http://support.blackboardcollaborate.com/ics/support/default.asp?deptID=8336&task=knowledge&questionID=2318

If you try to delete a recording that has no audio, the error message "An error occurred communicating with the SAS server. Please contact your administrator." appears.

The solution is to check the table mdl_elluminate_recordings and mdl_elluminate_recording_files and troubleshoot from there. 

Wednesday, August 14, 2013

How to fix the book module upgrade error

When upgrading from Moodle 2.2 to 2.4 sometimes it errors out with
Debug info: SELECT id,course FROM
{course_modules}
WHERE id IS NULL
[array (
)]
Error code: invalidrecord
Stack trace:
line 1335 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
line 1311 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
line 6644 of /lib/accesslib.php: call to moodle_database->get_record()
line 117 of /mod/book/db/upgradelib.php: call to context_module::instance()
line 169 of /mod/book/db/upgrade.php: call to mod_book_migrate_all_areas()
line 627 of /lib/upgradelib.php: call to xmldb_book_upgrade()
line 358 of /lib/upgradelib.php: call to upgrade_plugins_modules()
line 1524 of /lib/upgradelib.php: call to upgrade_plugins()
line 329 of /admin/index.php: call to upgrade_noncore()


To bypass this orphaned error issue, you need to edit the moodle/mod/book/db/upgradelib.php and insert on line 117

$cm = get_coursemodule_from_instance('book', $book->id);
if (empty($cm) || empty($cm->id))
{ continue; }

$context = context_module::instance($cm->id);

This would not fix the orphans, but the upgrade would at least continue properly

Thursday, July 25, 2013

Fix Microsoft SQL missing login name after db copy/move

To fix the missing login name, just execute this

EXEC sp_change_users_login 'UPDATE_ONE','Annie','Annie'

replace Annie with the name of the user

To find out the list of broken / orphaned users, you can execute this

EXEC sp_change_users_login 'REPORT'


On SQL 2005 and above, this is the query to fix

use dbname;
EXEC sp_change_users_login 'Auto_Fix', 'username', null, 'password'

Monday, July 1, 2013

Trace running php script

To see more details on running php script, you can just use
strace -p pid

Wednesday, June 5, 2013

Login using manual user to Moodle with Cas authentication

http://moodleurlhere/login/index.php?authCAS=NOCAS&username=admin

Change the moodleurlhere with your domain name

Monday, March 4, 2013

Find largest file in moodledata

SELECT DISTINCT filename, filepath, FORMAT( (filesize /1024 /1024), 1 ) AS filesize_MB, contenthash, component
FROM `mdl_files`
ORDER BY filesize DESC
LIMIT 0 , 30

Thursday, December 20, 2012

Apache subfolder setup

This tutorial is explain how to setup a subfolder but the location is not inside the html folder, instead, it can be located parallel to the html


Alias /subdirectory /path/to/real/subdirectory

Wednesday, December 19, 2012

How to setup cron for ELIS RLIP

This tutorial is to set cron to run every 5 minutes for the ELIS RLIP block

#crontab -e

then enter line below
5 * * * *  nice php /mnt/data/www/pathtomoodle/blocks/rlip/rlip_cron.php >/dev/null 2>&1


Tuesday, November 13, 2012

How to remove IP manually from cpanel

1 Bring down the ip first
for example ifconfig eth0:cp3 xxx.xx.xx.xx netmask 255.255.255.0 down

2. Edit /etc/ips and remove the line with the corresponding ip

3. Run this command /etc/init.d/ipaliases restart

Thursday, October 11, 2012

Some example for httpd.conf



  DocumentRoot /path/to/domainname
  ServerName domainname
  redirect permanent / https://domainname/
 Alias /sandbox /path/to/domainname/sandbox



The above is just an example on how to setup the virtualhost on apache
The Alias is like a subfolder inside the public_html but you can put the folder in parallel to the public_html.

Thursday, September 6, 2012

Wednesday, August 22, 2012

Recover mysql root password

You can recover MySQL database server password with following five easy steps.

Step # 1: Stop the MySQL server process.

Step # 2: Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password.

mysqld_safe --skip-grant-tables

Step # 3: Connect to mysql server as the root user.

Step # 4: Setup new mysql root account password i.e. reset mysql password.


mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit



Step # 5: Exit and restart the MySQL server.


Thursday, August 2, 2012

Mysql grant


mygrants()
{
  mysql -B -N $@ -e "SELECT DISTINCT CONCAT(
    'SHOW GRANTS FOR ''', user, '''@''', host, ''';'
    ) AS query FROM mysql.user" | \
  mysql $@ | \
  sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}'
}

Put the above command to /root/.bashrc and when typing mygrants command, it will show the mysql privilege

Tuesday, July 24, 2012

htaccess redirect to www

To redirect a domain from a non www to a www domain, just add .htaccess


RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


to reverse redirect a domain from a www to a non www


RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC]
RewriteRule ^(.*)$ http://my-domain.com/$1 [R=301,L]


Another way using the conf

redirect permanent / https://insert-url-of-your-site/

Example of using multiple url to point to the same site

  ServerName domain1.net
  DocumentRoot /opt/rlcache/www/moodle_prod
  Alias /sandbox /opt/rlcache/www/moodle_sand



  ServerName  domain2.net
  Redirect permanent / http://domain1.net/









Wednesday, July 18, 2012

Add column to existing table in mysql


ALTER TABLE contacts ADD email VARCHAR(60);

This first statement will add the email column to the end of the table. To insert the new column after a specific column, such as name, use this statement:

ALTER TABLE contacts ADD email VARCHAR(60) AFTER name;

If you want the new column to be first, use this statement:

ALTER TABLE contacts ADD email VARCHAR(60) FIRST;

To remove a column
ALTER TABLE table_name
DROP COLUMN column_name

Sunday, June 10, 2012

Create zip file in linux

zip -r archivefilename.zip foldertocompres/

Quick hint to use vi

vi Cheatsheet 
dd to delete line
/string Search forward for string
?string Search back for string
:s/pattern/string/flags Replace pattern with string according to flags.
g Flag - Replace all occurences of pattern
c Flag - Confirm replaces.
& Repeat last :s command

A to go to end of line and Insert mode
$ to go to end of line

I to go to first of line and Insert mode
0 to go to first of line

1G Move to the first line of the file
G Move to the last line of the file
nG Move to nth line of the file
:n Move to nth line of the file