How many lines of code does Moodle have?
The short answer is: core Moodle 2.6 has about 600k lines of code + 3rd party libraries.
Now, the long answer.
A lot of the Moodle code are 3rd party libraries that are copied mostly under “lib” directory and some other places – I have counted those separately. I have also not counted *-min.js and *-debug.js files as duplicates.
After stripping from those, here is the statistic for the core code for the latest Moodle (2.7dev build: 20131122):
The code above works just fine, you can access private properties of different object – as long as you’re the same class. PHP manual confirms the behaviour:
Members declared as private may only be accessed by the class that defines the member.
The purpose of this blog is to show how to enable search for multi-valued properties in advanced search form in Alfresco. Let’s assume that we are looking for authors and we want to find all the documents created by author John or Mary. This feature allows to do this in single query instead of two queries.
Solution
Multi-valued search is already supported in Alfresco, but requires additional configuration. This can be done by adding additional hidden field to advanced search form. The field should follow the name format prop:{name of the filed with values separated by commas}-mode and defines logical operator that should be used to replace commas.
In addition, hidden.ftl form control has to be modified to support providing field value in contextProperty parameter. The changes are presented below:
This blog describes how to create e-mail template in Alfresco and use it for sending e-mail.
Template
E-mail templates are kept in folder Company Home/Data Dictionary/Email Templates, but in general they can be kept in any folder. Let’s assume, that in our template we want to use some variables, which values will be passed during invocation of e-mail action. Our template is saved in Company Home/Data Dictionary/Email Templates/sample_template.ftl and is defined as follows:
Variable ‘firstName’ should be replaced with the name of user the message is send to.
E-mail send action
We will invoke e-mail sending action using Alfresco JavaScript API:
See the screencast below for the description of new moosh feature – code generation. You can download moosh from Moodle plugins, also see the documentation.
Imagine that you have few developers working on Java project. Code of the project is committed to GIT repository and there are ANT scripts implemented to facilitate builds and deployments of the system as well as additional activities that might be useful. The developers using this infrastructure push code changes to GIT repository and automatic build and deployment of the latest code version should be automatically deployed on Tomcat server. This blog describes simple automatic build system that users GIT hooks to invoke appropriate ANT tasks depending on files that were changed in the system.
Users
There are two users that are crucial to run the automatic builds:
git – this user is owner of GIT repository and the commits are made as git user
tomcat – this user should run Tomcat
To allow the deployments, which involve stopping and starting Tomcat server, git user should be able to run tomcat as tomcat user. This functionality can be enabled in /etc/sudoers file.
Run:
sudo visudo
and add the following line
git ALL = (tomcat) NOPASSWD: ALL
To run a command as Tomcat user type
sudo -u tomcat {command name}
If you set some variables you might want not to reset them once you run sudo command. To do so add variable names to sudoers file
Defaults env_keep += "JAVA_HOME"
Project structure
Let’s assume that our project has the following structure:
project – source of the project to be compiled and deployed
src – source code
configuration – Tomcat configuration files
git – GIT configuration files
post-receive – script to be invoked after push is made to GIT repository
build.xml – ant build script
Ant script
Let’s assume that ant script has following targets defined:
build-deploy – build the project and deploy it on Tomcat server
Depending on code changes the following targets should be run:
on change in project/src folder build-deploy tasks should run
on change in configuration folder deploy-configuration task should run
Git repository
Hooks
Git allows to run actions on several events, which mechanism is implemented using hooks. There are several hooks defined in git. Some of them are client side and some of them are server side. More information regarding hooks can be found here
Bare git repository is located on the server. Hooks are located in {git repository path}/hooks/. We are going to use server-side post-receive hook to make automatic builds. The post-receive hook runs after the entire process is completed and can be used to update other services or notify users. It takes a list of references that are being pushed from stdin.
The hooks will run as user which logs into GIT therefore it is important to ensure that tasks can be run as this user or user can run tasks as other user.
Configuration
To use ant build file (build.xml) and post-receive script, the checkout of the repository has to be done on the same server:
The checkout should be done as tomcat user.
Each time push will be made to the repository, the checkout repository should be updated (git pull) and then the files from the repository could be used for builds. Having both files in the repository (build.xml and post-receive) allows dynamic configuration changes and flexible build system without a need to make any changes on the server.
post-receive hook configuration
We can invoke post-receive script which is in our git repository by invoking the script from post-receive hook in GIT repository. To do so post-receive file should be created in {git repository path}/hooks/ and made executable. The file, which is in fact bash script, should include the following commands:
Automatic build script – post-receive
The following listing presents automatic build script. The script is located in GIT repository in git folder, so whenever it is changed the changes are automatically applied. The comments regarding parts of the script are within the code.
Bash and zsh both have a very neat feature for expanding a single word into more: brace expansion.
For the simplest example, imagine you need to move file.old as file.new. Normally you type:
Brace expansion can save you a little bit of typing:
The command actually executed will be identical to the previous one, “file.{old,new}” gets converted into “file.old file.new”.
You can also provide a number range inside the brace:
With a third parameter, the number will be increased by that much each time (step):
Only a zsh feature is padding. You can add leading zeros to generated number to make them all the same (character) size, by adding zero(s) to the third parameter:
Zsh offers even more flexibility after setting BRACE_CCL option – you can use range of characters as well:
I needed to locate current user’s home directory, to find and parse a config file like ~/config.ini. The current user is a user that is currently running a PHP CLI script. I have found a neat solution in drush, ready to copy & paste into your function:
Normally, when you want to redirect (standard) output of a script to a file, you run it with a redirection, like:
However – you can also accomplish the same from inside the script by using exec. The following will write “Test” and then current time into /tmp/out.log”
I try to keep the same .zshrc dotfile on all the machines I use. I store the “master” copy in SVN, so any improvements I make can easily go to other computers.
However, some parts of zshrc configuration only make sense for particular machine. To keep one common master copy but also allow for some “local” configuration, you can simply use an include in your .zshrc like this: