• log out

PHP Scripts

The APP_DIR/scripts directory is where you keep all the various command-line scripts for your app. Unlike the php files found in APP_DIR/web, these are not called from the web. These can include cron jobs and other scripts you run to perform tasks. Of course, they are namespaced. like everything else.

You will find a bunch of standard scripts in APP_DIR/scripts/Q, including:

  • install.php: install and update apps
  • configure.php: run this after cloning an app template
  • models.php: autogenerate and update the model classes from the database connections
  • combine.php: combine and compress CSS, JS and images for live environments
  • urls.php: update the APP_DIR/config/Q/urls.php which is used by native mobile apps to have faster start times.

Node.js Scripts

Your First app comes with a Node.js script named APP_DIR/script/First/First.js which is designed to work together with the PHP, as a background service that supports websockets, offline notifications, and more. If your app uses the "Users" and "Streams" plugins, a minimal Node.js server would start their servers and let them do the rest:

require('../Q.inc')(function(Q) {
  Q.plugins.Users.listen();
  Q.plugins.Streams.listen();
});

Typically, you'll want to start this server with something like forever -a First.js . As a result, your app will be instantly enhanced with real-time responsiveness, and much more.

Update Scripts

Whether you're using MySQL or another database, the APP_DIR/script/First/ directory can contain scripts to update between versions of your app. (And similarly for plugins.) Inside that directory, they are named $version-$connection.$dbms

Typically, a plugin will have at most one Db connection, which is named after it, but it may have more. For example, when updating the Fancy plugin from version 1.2 to 1.4, the following scripts would be run in order, if they exist:
scripts/Fancy/1.3-Fancy.mysql
scripts/Fancy/1.4-Fancy.mysql
scripts/Fancy/1.3-Users.mysql.php
scripts/Fancy/1.4-Users.mysql.php

The mysql scripts are executed after replacing {{prefix}} with the prefix from the connection. The php scripts are executed as command-line PHP scripts. A typical mysql update script would look like:

ALTER TABLE `{{prefix}}message`
ADD `sent` INT NOT NULL DEFAULT '0',
ADD `viewed` INT NOT NULL DEFAULT '0';

To make changes to the database, place your script in the folder and then edit config/app.json to increment the app's version and don't forget to add the database connection to the app or plugin.