Drupal Updater Script

From WolfTech
Revision as of 09:29, 11 December 2008 by Abstein2 (talk | contribs) (→‎Settings)
Jump to navigation Jump to search

The Drupal Updater Script is a PHP command line script used for keeping multiple Drupal installs current and updated based on another Drupal install you are running. This install (which we'll call the Source Drupal) should but the most recent, updated version Drupal that has had any necessary file modifications performed.

The script performs the following actions:

  • Reads the Source Drupal install and determines the current version of Drupal that is installed
  • Begins processing, one by one, through the list of user-defined Drupal installs (which we'll call Patch Drupals), detecting versions and connecting to database
    • If the version number is less than or equal to the Source Drupal Version, the update continues.
    • If the version number is greater than the Source Drupal Version, the update stops
  • Creates a tarball containing the Patch Drupal currently being examined that contains all the files in the Patch Drupal's defined path
  • Dumps contents of database to an SQL file which is then added to the tarball.
  • Replaces any .htaccess with a customized .htaccess that only allows our cron server access; effectively taking the site down temporarily
  • Finds and deactivates all non-core Drupal modules
  • Updates the database to set the Patch Drupal into "Maintenance Mode"
  • Clears internal Drupal cache
  • Copies all files (excluding /sites/default) from the Source Drupal path to the Path Drupal path
  • Re-activate all non-core Drupal modules
  • Take site out of "Maintenance Mode"
  • Checks for any module conflits:
    • Any modules in the /sites/all/modules folder of the Source Drupal will also be copied to the Path Drupal's /sites/all/modules folder. This is meant as a method to push approved modules to our other Drupal installs and make sure that all other Drupals are also using the updated, working modules.
    • The following happens if a Drupal modules exists in the Patch Drupal's /sites/all/modules and /sites/default/modules folders:
  • The /sites/all and /sites/default modules both have their versions checked. If the module version in /sites/all is greater than the version in /sites/default, the version in /sites/default is deleted and all database entries pointing to its path and changed to the /sites/all version. Any updates that actually need to be run in order to upgrade versions will be handled in a bit.
  • Clears internal cache again
  • Detects all settings.php files in your /sites folder (generally just /sites/default/settings.php) and edits the $update_free_access variable to TRUE. This is necessary for the script to run the update.php file manually. This script updates the Patch Drupal to recognize the new files we copied from the Source Drupal, run any database updates that are necessary, and also run any module updates.
  • Performs any automatic module installs and activations we requested in the Patch Drupal definition.
  • Changes any settings.php files that the script previously modified the value of $update_free_access back to $update_free_access = FALSE.
  • If it exists, restore the original .htaccess file into position
  • Your updated Patch Drupal should now be up and running.


Settings

There are two settings arrays the need to be paid attention to $source and $patchList. $source is the Source Drupal whereas each entry of $patchList is a Patch Drupal

$source

	$source = array(
			'db' => 'drupal_source', 			/* your Drupal database */
			'db_user' => 'drupal_source', 			/* your Drupal database username */
			'db_pass' => '???????????',			/* your Drupal database password */
			'db_host' => 'localhost', 			/* your Drupal database host */
			'path' => '/path/to/drupal files', 		/* your Drupal filepath */
			'url' => 'http://www.wolftech.ncsu.edu/', 	/* your Drupal web address */
			'version' => '', 				/* leave blank */
			'connection' => false 				/* leave as false */
		);

$patchList

	$patchList = array(
			array(
				'db' => 'drupal_patch', 				/* your Drupal database */
				'db_user' => 'drupal_patch', 				/* your Drupal db username */
				'db_pass' => '????????', 				/* your Drupal db password */
				'db_host' => 'localhost', 				/* your Drupal database host */
				'path' => '/path/to/existing/drupal', 			/* your Drupal filepath */
				'url' => 'http://www.wolftech.ncsu.edu/drupal', 	/* your Drupal web address */
				'drupal_user' => 'admin', 				/* Admin Drupal username */
				'drupal_pass' => '????', 				/* Admin Drupal database */
				'autoInstallModules' => array() 			/* Modules to automatically
											install and ensure are running;
											Enter each as an array element
											Example: array('guarddog', 'wrap')  */
			)
				
		);

Note: If you do not specify any autoInstallModules, you do not need to enter your Admin Drupal username ('drupal_user') or Admin Drupal Password ('drupal_pass'). The autoInstallModules functionality requires Drupal to log in as a user.