This is a how-to geared especially toward our add-on developers, but it'll be useful to anyone who wants to create a cycling concrete5 demo that automatically resets. In this how-to I'll explain how to prepare a database for the demo, setup special demo-specific permissions overrides, create a demo administrative user, install one or more add-ons along with the demo, and provide a script that can be run at any time to reset the demo.
Note: This requires concrete5 5.5.0 and greater. Another how-to is available for older versions of concrete5.
This how-to references a reset script and permissions overrides. You can download these files here:
Download Reset Script and Permissions Overrides
First I create the database:
CREATE DATABASE concretedemo;
Then I grant permissions to the user on the database:
GRANT ALL ON concretedemo.* TO concretedemo@localhost IDENTIFIED BY 'concretedemo';
Download the latest version of concrete5, unzip it to the web directory that will house your demo, and install it.
We want our demo user to be added to the Administrators group, so they can access the dashboard, but we don't want to give out full and complete access. We don't want sitewide settings to be looked at, or file access permissions to change, for example. Fortunately there's a little-used feature that allows us to lock down single page permissions at the time of their creation: access.xml files. These files live in the specific controllers/ directory for the given single page.
A sample access.xml file looks like this:
<guests canRead="0" ></guests>
<registered canRead="0" ></registered>
<administrators canRead="0" canWrite="0" canAdmin="0" ></administrators>
This locks the admnistrators group out of accessing the /dashboard/files/access page.
In the .zip file above, you'll see a controllers/ directory. Copy the contents of this controllers/ directory into your root controllers/ directory. The next time your demo site is reset, these access restrictions will be in place.
Install "Reset" Script
Also contained within the .zip file above is a reset script. When run, this script does the following:
- Removes config/site.php
- Removes all files in the files/ directory
- Removes all tables in the demo database
- Reinstalls concrete5 with the values specified in the reset script, and the database information that you originally installed concrete5 with. Permission overrides described in "Lockdown Dashboard" are applied
- Creates a second administrative user in the Administrators group
- Locks down file permissions
- Disables site emails
Installs specified add-ons into the site.
Before you install
Please, rename the reset script! Anyone who hits the URL of the reset script will be able to reset your demo.
Configure Reset Script
There are a number of values at the beginning of the script that deserve explanation.
- DEMO_SETUP_SITE: This constant will determine the name of your site.
- DEMO_DB_SERVER: Your demo's MySQL server. Typically "localhost".
- DEMO_DB_USERNAME: The username for your demo's MySQL user. e.g. "concretedemo".
- DEMO_DB_PASSWORD: The password for your demo's MySQL user. e.g. "concretedemo".
- DEMO_DB_DATABASE: Your demo's MySQL database. e.g. "concretedemo".
- DEMO_STARTING_POINT: A starting point (sample_content, blank, a custom one) that will be installed as the sample content for this site.
- DEMO_ADMIN_EMAIL: An email address for the admin account that will be created when your site is reset.
- DEMO_ADMIN_PASSWORD: The password for your "admin" user account.
- DEMO_USER_USERNAME: The username for your "demo" account. This is the account you will give out to users who wish to demo your software.
- DEMO_USER_EMAIL: The email address for your "demo" account.
- DEMO_USER_PASSWORD: The password for the "demo" user.
- DEMO_PASSWORD_SALT: A long string that needs to be in place in this script.
- PACKAGES_TO_INSTALL: A comma-separated list of package handles of all add-ons in the local packages/ directory you wish to install every time the demo site is reset.
Scheduling this Script
It is easy to cron this script so that it will clean out data every hour. Something like this can be entered into a crontab on a Linux server. For example, if your reset script is
You can can make it run every hour on the hour with
0 * * * * /usr/bin/wget -T 0 -q http://www.yoursite.com/reset_128273282.php
in your crontab file.
That's it! Now you should have a fully functional concrete5 demo with a full admin account, a limited admin account, and any add-ons preinstalled that you wish to demonstrate.