Updating modules

Recommended Posts

Is it possible to update a module without it being in the module directory?

The same way that one in the module directory is.

Share this post

Link to post
Share on other sites

Not sure I follow...yes, you can update by:

  1. Pointing to a URL (e.g. GitHub download link to the module)
  2. Uploading from a local folder...

ProcessWire will then update it. Watch out for folder names though, sometimes the module can end up at 'ProcessMyModule' rather than 'MyModule'. In such cases you should get an error about 'cannot redeclare class...'

Share this post

Link to post
Share on other sites

Read this http://modules.processwire.com/export-json/

You have the option to change the following in your config.php

$config->moduleServiceURL = 'http://modules.processwire.com/export-json/';
$config->moduleServiceKey = (__NAMESPACE__ ? 'pw300' : 'pw280');

Example for a request

created from moduleServiceURL, ModuleClassName, moduleServiceKey (GET Parameter)

  • Like 1

Share this post

Link to post
Share on other sites

Yes for sure. Sorry for answering unclear. I just wanted to say that the information about the module version is pulled from the processwire modules directory by default.

You could add a hook before ProcessModule::executeEdit() and change this only if the classname of the event object matches your specific module.

Share this post

Link to post
Share on other sites

Thank you @kixe I managed to achieve what I need.

Any idea what the key (pw300/pw200) is doing?

For whoever is interested. In my module I added

public function init() {
	wire()->addHookBefore("ProcessModule::execute", $this, "changeModuleService");

public function changeModuleService(HookEvent $event) {
	if($_GET["update"] === "ModuleName") {
		wire("config")->moduleServiceURL = "http://domain.tld/";
		wire("config")->moduleServiceKey = (__NAMESPACE__ ? "pw300" : "pw280");

And the module autoload property is set to "autoload" => "path=/admin/module/"

Now whenever the "check for updates" link is clicked it searches for a new version on domain.tld/ModuleName, this has to return a json similar to the one posted above.

  • Like 2

Share this post

Link to post
Share on other sites

Just because it's Monday:


 * ProcessWire module.
 * Allow depending modules to be updated from non-standard repositories.
 * In absence of this module, your module will continue to work but updates
 * will point at the regular repository. If you want to avoid that, add
 * a "requires" entry in your module
 * To trigger the custom update routines, add an array "extendedUpdate" to
 * your getModuleInfo array. It can either contain a "url" entry with the
 * URL to the JSON data that describes the available update, or a "customMethod"
 * entry with the name of a public method in your module that returns that
 * URL.
 * If you go the "url" way, the value there is run through wirePopulateStringTags.
 * You can add placeholders for all of the modules moduleInfo values, the module's
 * configuration values, the "moduleServiceKey" (PW base version, i.e. pw300, pw280 etc.)
 * and the module's name as, yeah, you guessed it, "name".
 * If you use customMethod, it gets passed an associative array with all these values.
 * A simple example for a module using custom updates:
 * class TestModule extends WireData implements Module {
 * 	public static function getModuleInfo() {
 * 		return array(
 * 			"title"				=>	_("Test Module"),
 * 			"summary"			=>	_("Test for a module with a custom update location"),
 * 			"version"			=>	"0.0.1",
 * 			"requires"			=>	array("ModuleUpdateCustomUrl"),
 * 			"extendedUpdate"	=>	array(
 * 				"url"				=>	"https://bitpoet.ddns.net/update/{name}.json?apiVersion={moduleServiceKey}",
 *				// Alternative way to generate the URL through a method in your module:
 * 				//"customMethod"	=>	"generateUrl"
 * 			)
 * 		);
 * 	}
 * 	public function generateUrl($data) {
 * 		return "https://bitpoet.ddns.net/update/" . $data['name'] . ".json?apiVersion=" . $data['moduleServiceKey'];
 * 	}
 * }
 * A somewhat minimal JSON example response for the test module above:
 * {
 *    "status":"success",
 *    "class_name":"TestModule",
 *    "module_version":"0.0.2",
 *    "authors":[
 *       {
 *          "title":"BitPoet"
 *       },
 *       {
 *          "title":"Anonymous"
 *       }
 *    ],
 *    "pw_versions":[
 *       {
 *          "name":"2.7"
 *       },
 *       {
 *          "name":"2.8"
 *       },
 *       {
 *          "name":"3.0"
 *       }
 *    ],
 *    "download_url":"https://bitpoet.ddns.net/update/TestModule_0.0.2.zip",
 *    "release_state":{
 *       "title":"Beta"
 *    },
 *    "summary":"Test for a module with a custom update location",
 *    "module_home":"https://bitpoet.ddns.org/modules/TestModule"
 * }
 * For a complete example, see the live data from the official repo, e.g.
 * http://modules.processwire.com/export-json/Helloworld/?apikey=pw300
 * The response must either return a property "success" with a true value
 * or populate an "error" property with a description of what went wrong.

class ModuleUpdateCustomUrl extends WireData implements Module {
	public static function getModuleInfo() {
		return array(
			"title"			=>	_("Module Update from Custom Url"),
			"summary"		=>	_("Extension module that allows modules to be updated from non-standard repos."),
			"version"		=>	"0.0.4",
			"autoload"		=>	true,

	public function init() {
		$this->addHookBefore("ProcessModule::execute", $this, "hookProcessModuleExecute_customUpdate");
	public function hookProcessModuleExecute_customUpdate(HookEvent $event) {
		if($this->input->get->update) {
			$name = $this->sanitizer->name($this->input->get->update); 
			$info = $this->modules->getModuleInfo($name);
			if(! $info["extendedUpdate"]) return;
			if(! isset($info["extendedUpdate"]["url"]) && !isset($info["extendedUpdate"]["customMethod"])) {
				$this->error($this->_('Neither URL nor custom method set in extendedUpdate configuration in module info'));
			$event->return = $this->downloadDialog($name, $info);
			$event->replace = true;

	public function downloadDialog($name, $info) {
		$redirectURL = "./edit?name=$name";
		$className = $name; 
		$cfgdata = $this->modules->getModuleConfigData($name);
		$params = array_merge($info, $cfgdata);
		$params["moduleServiceKey"] = $this->wire('sanitizer')->name($this->wire('config')->moduleServiceKey);
		$params["name"] = $name;

		if(isset($info["extendedUpdate"]["customMethod"])) {
			$method = $info["extendedUpdate"]["customMethod"];
			$module = $this->modules->get($name);
			$url = $module->$method($params);
		} else {
			$url = trim(wirePopulateStringTags($info["extendedUpdate"]["url"], $params));
		$http = $this->wire(new WireHttp());
		$data = $http->get($url); 
		if(empty($data)) {
			$this->error($this->_('Error retrieving data from web service URL') . ' - ' . $http->getError());
			return $this->session->redirect($redirectURL);
		$data = json_decode($data, true); 
		if(empty($data)) {
			$this->error($this->_('Error decoding JSON from web service')); 
			return $this->session->redirect($redirectURL);
		if($data['status'] !== 'success') {
			$this->error($this->_('Error reported by web service:') . ' ' . $this->wire('sanitizer')->entities($data['error']));
			return $this->session->redirect($redirectURL);	
		$form = $this->buildDownloadConfirmForm($data);
		return $form->render(); 			
	public function buildDownloadConfirmForm($data) {
		$warnings = array();
		$authors = '';
		foreach($data['authors'] as $author) $authors .= $author['title'] . ", ";
		$authors = rtrim($authors, ", ");

		$compat = '';
		$isCompat = false;
		$myVersion = substr($this->wire('config')->version, 0, 3);
		foreach($data['pw_versions'] as $v) {
			$compat .= $v['name'] . ", ";
			if(version_compare($v['name'], $myVersion) >= 0) $isCompat = true;
		$compat = trim($compat, ", ");
		if(!$isCompat) $warnings[] = $this->_('This module does not indicate compatibility with this version of ProcessWire. It may still work, but you may want to check with the module author.');

		$form = $this->wire('modules')->get('InputfieldForm');
		$form->attr('action', './download/');
		$form->attr('method', 'post');
		$form->attr('id', 'ModuleInfo');
		$markup = $this->wire('modules')->get('InputfieldMarkup');
		$installed = $this->modules->isInstalled($data['class_name']) ? $this->modules->getModuleInfoVerbose($data['class_name']) : null;
		$moduleVersionNote = '';
		if($installed) {
			$installedVersion = $this->formatVersion($installed['version']); 
			if($installedVersion == $data['module_version']) {
				$note = $this->_('Current installed version is already up-to-date'); 
				$installedVersion .= ' - ' . $note;
			} else {
				if(version_compare($installedVersion, $data['module_version']) < 0) {
					$this->message($this->_('An update to this module is available!')); 
				} else {
					$moduleVersionNote = " <span class='ui-state-error-text'>(" . $this->_('older than the one you already have installed!') . ")</span>";
		} else {
			$installedVersion = $this->_x('Not yet', 'install-table');

		$table = $this->wire('modules')->get('MarkupAdminDataTable');
		$table->row(array($this->_x('Class', 'install-table'), $this->wire('sanitizer')->entities($data['class_name'])));
		$table->row(array($this->_x('Version', 'install-table'), $this->wire('sanitizer')->entities($data['module_version']) . $moduleVersionNote));
		$table->row(array($this->_x('Installed?', 'install-table'), $installedVersion)); 
		$table->row(array($this->_x('Authors', 'install-table'), $this->wire('sanitizer')->entities($authors)));
		$table->row(array($this->_x('Summary', 'install-table'), $this->wire('sanitizer')->entities($data['summary'])));
		$table->row(array($this->_x('Release State', 'install-table'), $this->wire('sanitizer')->entities($data['release_state']['title'])));
		$table->row(array($this->_x('Compatibility', 'install-table'), $this->wire('sanitizer')->entities($compat)));
		// $this->message("<pre>" . print_r($data, true) . "</pre>", Notice::allowMarkup); 
		$installable = true; 
		if(!empty($data['requires_versions'])) {
			$requiresVersions = array();
			foreach($data['requires_versions'] as $name => $requires) {
				list($op, $ver) = $requires;
				$label = $ver ? $this->sanitizer->entities("$name $op $ver") : $this->sanitizer->entities($name);
				if($this->modules->isInstalled("$name$op$ver") || in_array($name, $data['installs'])) {
					// installed
					$requiresVersions[] = "$label <i class='fa fa-fw fa-thumbs-up'></i>";
				} else if($this->modules->isInstalled($name)) {
					// installed, but version isn't adequate
					$installable = false;
					$info = $this->modules->getModuleInfo($name);
					$requiresVersions[] = $this->sanitizer->entities($name) . " " . $this->modules->formatVersion($info['version']) . " " . 
						"<span class='ui-state-error-text'>" . $this->sanitizer->entities("$op $ver") . " " . 
						"<i class='fa fa-fw fa-thumbs-down'></i></span>";
				} else {
					// not installed at all
					$requiresVersions[] = "<span class='ui-state-error-text'>$label <i class='fa fa-fw fa-thumbs-down'></i></span>";
					$installable = false; 
			$table->row(array($this->_("Requires"), implode('<br />', $requiresVersions))); 
			if(!$installable) $this->error("Module is not installable because not all required dependencies are currently met."); 
		if(!empty($data['installs'])) {
			$installs = $this->sanitizer->entities(implode("\n", $data['installs'])); 
			$table->row(array($this->_("Installs"), nl2br($installs))); 

		$links = array();

		$moduleName = $this->wire('sanitizer')->entities1($data['name']);
		if($data['module_home']) {
			$moduleURL = $this->wire('sanitizer')->entities($data['forum_url']);
			$links[] = "<a target='_blank' href='$moduleURL'>" . $this->_('More Information') . "</a>";

		if($data['project_url']) {
			$projectURL = $this->wire('sanitizer')->entities($data['project_url']);
			$links[] = "<a target='_blank' href='$projectURL'>" . $this->_('Project Page') . "</a>";

		if($data['forum_url']) {
			$forumURL = $this->wire('sanitizer')->entities($data['forum_url']);
			$links[] = "<a target='_blank' href='$forumURL'>" . $this->_('Support Page') . "</a>";

		if(count($links)) $table->row(array($this->_x('Links', 'install-table'), implode('  /  ', $links)));

		if($data['download_url']) {
			$downloadURL = $this->wire('sanitizer')->entities($data['download_url']);
			$table->row(array($this->_x('ZIP file', 'install-table'), $downloadURL));
			$warnings[] = $this->_('Ensure that you trust the source of the ZIP file above before continuing!');
		} else {
			$warnings[] = $this->_('This module has no download URL specified and must be installed manually.');

		foreach($warnings as $warning) {
			$table->row(array($this->_x('Please Note', 'install-table'), "<strong class='ui-state-error-text'> $warning</strong>"));

		$markup->value = $table->render();

		if($installable && $data['download_url']) {
			$btn = $this->wire('modules')->get('InputfieldSubmit');
			$btn->attr('id+name', 'godownload');
			$btn->value = $this->_("Download and install");
			$btn->icon = 'cloud-download';
			$btn->value .= " ($data[module_version])";
			$this->session->ProcessModuleDownloadURL = $data['download_url'];
			$this->session->ProcessModuleClassName = $data['class_name'];
		} else {

		$btn = $this->wire('modules')->get('InputfieldButton');
		$btn->attr('name', 'cancel');
		$btn->href ="./edit?name=$data[class_name]";
		$btn->value = $this->_("Cancel"); 
		$btn->icon = 'times-circle';
		$btn->class .= ' ui-priority-secondary';

		$form->description = $this->wire('sanitizer')->entities($data['title']); 
		return $form;

	 * Format a module version number from 999 to 9.9.9
	 * @param string $version
	 * @return string
	protected function formatVersion($version) {
		return $this->wire('modules')->formatVersion($version); 


Created with massive theft of code from ProcessModule.module;)

I'm going to toy around with this in our local environment and see if I can stitch together a nice workflow with the local git repo and a post-receive hook (once I find the time).

  • Like 3

Share this post

Link to post
Share on other sites

Ask @ryan about the apikey. Maybe its just an option to limit requests in the future if needed. Currently only pw300 and pw280 is valid. I didn't check if there is a different return.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      I got tired of having to open the link dialog in CKEditor in order to check where a link is pointing to, so made this simple plugin.
      Link Hover
      A plugin for CKEditor. Shows the href attribute of a link in a tooltip when the link is hovered. This saves you from having to open the link dialog in order to check where a link points to.

      This readme assumes installation in ProcessWire CMS.
      The plugin folder must be named "linkhover" – if necessary, rename the folder to remove the "-master" suffix added by GitHub. Copy the "linkhover" folder to /site/modules/InputfieldCKEditor/plugins/
      In the field settings for each CKEditor field that you want to activate the plugin for, check the "linkhover" checkbox at Input > Plugins > Extra Plugins
    • By neosin
      I've been reading through the tutorials and have created an admin module based on the ProcessHello example module.
      I have a few questions regarding how to do a few things with the module that are not obvious or covered by the processhello tutorial.
      Outline of expected module functionality:
      The custom module admin setup page should contain a list of its editable pages. CMS users will be able to add/edit/delete pages of this module. The modules editable pages use the same defined fields. The editable pages data will need to be available for use by another custom module. This custom module (called "Stream Encoders") will handle creating/updating/deleting of "Stream Encoders".
      The encoders contain various fields such as encoder name, operational status (is it on or off) and brightcove asset ID
      A second module in "admin>setup" called "Video Streams" will handle creating/updating/deleting/scheduling of "Video Streams".
      Each video stream belongs to a video encoder and uses some of the settings from the encoder selected, such as the encoder title and the brightcove asset ID which on the frontend are used to display the video stream.
      My noob questions:
      Since they are not "pages" in the navigation tree, how do I define these "encoders" to add them to the custom stream encoders module? I don't believe my custom modules should be under "Setup", is it possible to have custom menus in the admin? It's fine if they can't but it would be more intuitive if they had their own menus in the admin instead of living under "Setup". Without having a specific page on the frontend for video streams, how would I access the data for a specific video stream from the home page? for example if I wanted to display a specific or random video stream in a sidebar on the homepage. Are there any tutorials on using scheduling with custom modules? The video streams can be scheduled or turned on/off as desired by the CMS users. thank you in advance
    • By BitPoet
      The module has been lying around on GitHub for some time now, so I thought I'd give it its own forum topic so I can give it a module list entry.
      Symmetric encryption for text based fields (supports multi language fields).
      Module page.
      Link to the GitHub repo.
      This module adds an encryption option to all text fields (and those derived from FieldtypeText).
      Field contents are encrypted using a symmetric key when a page is saved and decrypted when loaded from the database.
      The module by default uses sodium (if loaded) in PHP versions >= 7.2, otherwise it falls back to the bundled phpseclib.
      Multi-Language fields are supported too.
      Setting a field to encrypted and saving values in those fields is a one-way road!
      Once encrypted, the contents cannot be unencrypted without writing a program to do so. Disabling the encryption option on a field after the fact gets you encrypted "garbage".
      Download the zipped module through the green button at the top right of the GitHub repo or (once available there) from the official PW module repository Extract in its own directory under site/modules. In the backend, click "Modules" -> "Refresh", then install "Symmetric Encryption for Text Fields". Go to module settings. An appropriately sized, random key will be generated if this is your first use. Copy the supplied entry into site/config.php Add fields or configure already present fields. On the "Details" tab you can enable encryption for the field in question Edit a page with such a field, enter a value there, save and enjoy Existing, unencrypted values are left untouched until a new value is saved. That way, you can do a smooth upgrade to encryption, but you have to save all pre-populated pages to have their values encrypted in the database. Thus it is recommended to avoid adding encryption to already populated fields.
      Advanced Usage
      You can hook after SymmetricEncryptedText::loadKey to retrieve your key from somewhere else, e.g. a different server.
    • By BitPoet
      After building the ProcessMentions module and another autocomplete module for images, I found that I am going to need even more of these, but things were going to get repetitive. So I refactored the whole thing into a basic autocompletion module and individual "actions".
      The result is Autocomplete for CKEditor (GitHub).
      To try out,
      Install the module and actions

        Enable actions in the settings of any CKEditor field

        Edit a page with this field, type "@" and some characters for the  and enjoy
      There are still a few things I need to implement. ATM, it only supports single characters as triggers for the autocomplete. I'd like to change that to combinations so I don't run out of special characters at some point. I also have to add a few more configuration options (like search only at the beginning or also in the middle of the searched string). The documentation for custom styling also needs some work.
      I have tried to keep things generic. Implementing your own actions should be quite straight forward. The README at GitHub illustrates the main steps and the supplied action classes have inline documentation. I would love to get some feedback or even see some third party InlineCompleteAction implementations.
    • By Inxentas
      I love the option to export fields via the CMS, and wondered about using that export data in a module. Basicly, I'd want to configure a field using the CMS and then paste it's export data in the module code as a string, or save it in a seperate file I can read from the module code. Once I have that string as a variable or file, I'd want to run the same code the import option does... but then from my module code's install method!
      Is that possible? It would save a lot of time configuring fields through the API.