Custom module install error

On 1.8.3 I am creating a custom module to pull weather from Weather Underground and every time I try to install the module, I get the following error message:

Class Xibo\Custom\Wunderground\Wunderground not found

Instead of hacking the module code into the installation, I am trying to have all the code in /custom. In /custom I have the wunderground.json file containing:

{
  "title": "Weather Underground",
  "author": "Virginia Tech",
  "description": "Displays weather information from Weather Underground",
  "name": "wunderground",
  "class": "Xibo\\Custom\\Wunderground\\Wunderground"
}

I added an additional \ in the class line before the last Wunderground because without it the title shows as a hyphen in the install Module window. (https://xibo.org.uk/manual/en/advanced_modules.html shows it without the extra \ ) After that I created a file called Wunderground.php in \custom\Wunderground\ and tried to run the install. That file starts with the following code:

<?php
/*
 * Weather Underground Weather Widget
 * Copyright (C) 2018 - Virginia Tech
 *
 * The intellectual property of this file is owned by
 * Virginia Polytechnic Institute and State University 
 */
namespace Xibo\Widget;

use Respect\Validation\Validator as v;
use Xibo\Entity\Media;
use Xibo\Exception\NotFoundException;
use Xibo\Factory\ModuleFactory;

class Wunderground extends ModuleWidget
{
    protected $codeSchemaVersion = 1;

    /**
     * Install or Update this module
     * @param ModuleFactory $moduleFactory
     */
    public function installOrUpdate($moduleFactory)
    {
        if ($this->module == null) {
            // Install
            $module = $moduleFactory->createEmpty();
            $module->name = 'Weather Underground';
            $module->type = 'wunderground';
            $module->class = 'Xibo\Custom\Wunderground\Wunderground';
            $module->description = 'Weather Underground Widget';
            $module->imageUri = 'forms/library.gif';
            $module->enabled = 1;
            $module->previewEnabled = 1;
            $module->assignable = 1;
            $module->regionSpecific = 1;
            $module->renderAs = 'html';
            $module->schemaVersion = $this->codeSchemaVersion;
            $module->settings = [];
		$module->viewPath = '../custom/Wunderground';
            $module->defaultDuration = 60;

            $this->setModule($module);
            $this->installModule();
        }

        // Check we are all installed
        $this->installFiles();
    }

Any thoughts as to what is wrong and is causing the error on install?

It would be best to upgrade to 1.8.4 and then follow the guide https://xibo.org.uk/manual/en/advanced_modules.html

We did make several changes to how custom modules work and can be added in 1.8.4.

With that being said, I’d guess that namespace is wrong it should be Xibo\Custom not Xibo\Widget

Peter,

I will go and and upgrade this evening or tomorrow. Hopefully that will fix the issues. Just for fun, I went ahead and modified the Wunderground.php file in Custom\Wunderground to correct the namespace. When I tried that, I got an error regarding the line class Wunderground extends ModuleWidget

I tried changing that to class Wunderground extends \Xibo\Widget\ModuleWidget and class Wunderground extends Xibo\Widget\ModuleWidget neither of which worked (PHP error – could not find the ModuleWidget class). Next I added use Xibo\Widget\ModuleInterface; and tried both extends options. Again,neither worked. I will let you know after I upgrade to 1.8.4 and see if that fixes the issue.

So after the upgrade I am still getting install errors. Would it be possible to post an example of the start of a custom module (namespace, use clauses, class definition and installOrUpdate? Thanks.

Could you post those code snippets of what you currently have and what is the error you get please?

custom\wunderground-dev.json

{
  "title": "Weather Underground Dev",
  "author": "Joseph K. Goodman",
  "description": "Displays weather information from Weather Underground",
  "name": "wunderground-dev",
  "class": "Xibo\\Custom\\Wunderground-dev\\Wunderground-dev"
}

Beginning of custom\Wunderground-dev\Wunderground-dev.php

<?php
/*
 * Weather Underground Weather Widget
 * Copyright (C) 2018 - Joseph K. Goodman
 *
 * The intellectual property of this file is owned by
 * Virginia Polytechnic Institute and State University 
 */
namespace Xibo\Custom;

use Respect\Validation\Validator as v;
use Xibo\Entity\Media;
use Xibo\Exception\NotFoundException;
use Xibo\Factory\ModuleFactory;

class Wunderground-dev extends ModuleWidget
{
    protected $codeSchemaVersion = 1;

    /**
     * Install or Update this module
     * @param ModuleFactory $moduleFactory
     */
    public function installOrUpdate($moduleFactory)
    {
        if ($this->module == null) {
            // Install
            $module = $moduleFactory->createEmpty();
            $module->name = 'Weather Underground';
            $module->type = 'wunderground-dev';
            $module->class = 'Xibo\Custom\Wunderground-dev';
            $module->description = 'Weather Underground Dev';
            $module->imageUri = 'forms/library.gif';
            $module->enabled = 1;
            $module->previewEnabled = 1;
            $module->assignable = 1;
            $module->regionSpecific = 1;
            $module->renderAs = 'html';
            $module->schemaVersion = $this->codeSchemaVersion;
            $module->settings = [];
			$module->viewPath = '../custom/Wunderground-dev';
            $module->defaultDuration = 60;

            $this->setModule($module);
            $this->installModule();
        }

        // Check we are all installed
        $this->installFiles();
    }

The error message I get when trying to install is:

Class Xibo\Custom\Wunderground-dev\Wunderground-dev not found

Earlier when I was trying to install and it could find the class (not sure what changed) I received a PHP error about not being able to find the ModuleWidget class.

Please be aware that your file extends AGPLv3 code and therefore must also be AGPLv3 licensed. I’m sure you’re aware, but just in case! :slight_smile:

If your file is stored in: /custom/Wunderground-dev/ then the namespace of the file must be Xibo\Custom\Wunderground-dev. Each folder you add is represented in the namespace.

Once you are inside a namespace you need to reference classes outside of it properly - either with a use statement at the top, or each time you reference the class (this is pretty standard across all programming languages).

use Xibo\Widget\ModuleWidget;

Should be fine.

Dan,

I corrected the Wunderground-dev.php (located in /custom/Wunderground-dev) to the following:

namespace Xibo\Custom\Wunderground-dev;

use Respect\Validation\Validator as v;
use Xibo\Entity\Media;
use Xibo\Exception\NotFoundException;
use Xibo\Factory\ModuleFactory;
use Xibo\Widget\ModuleWidget;
 
class Wunderground-dev extends ModuleWidget

When I try to install, I get the error Class Xibo\Custom\Wunderground-dev\Wunderground-dev not found Since I am running on Linux, could capitalization of the C in custom or W in wunderground-dev be causing the issue?

Also, yes, I am aware of the requirements AGPL3. I expect that once the module is done and the IP office approves, I will make the module publicly available.

1 Like

Anything after /custom needs to be correctly cased.

On second look I think its probably your - causing an issue, your namespace/classname/folder should be alpha numeric with only _ characters as necessary.

WundergroundDev would be in keeping with the rest of the Xibo code base.

Dan,

That fixed the install issue, however now I get the following error whenever I try to design a layout:

Class Xibo\Custom\WundergroundDev not found

/custom/WundergroundDevWundergroundDev.php

namespace Xibo\Custom\WundergroundDev;

use Respect\Validation\Validator as v;
use Xibo\Entity\Media;
use Xibo\Exception\NotFoundException;
use Xibo\Factory\ModuleFactory;
use Xibo\Widget\ModuleWidget;

class WundergroundDev extends ModuleWidget
{
    protected $codeSchemaVersion = 0.1;

    /**
     * Install or Update this module
     * @param ModuleFactory $moduleFactory
     */
    public function installOrUpdate($moduleFactory)
    {
        if ($this->module == null) {
            // Install
            $module = $moduleFactory->createEmpty();
            $module->name = 'Weather Underground';
            $module->type = 'wundergrounddev';
            $module->class = 'Xibo\Custom\WundergroundDev';
            $module->description = 'Weather Underground Dev';
            $module->imageUri = 'forms/library.gif';
            $module->enabled = 1;
            $module->previewEnabled = 1;
            $module->assignable = 1;
            $module->regionSpecific = 1;
            $module->renderAs = 'html';
            $module->schemaVersion = $this->codeSchemaVersion;
            $module->settings = [];
			$module->viewPath = '../custom/WundergroundDev';
            $module->defaultDuration = 60;

            $this->setModule($module);
            $this->installModule();
        }

        // Check we are all installed
        $this->installFiles();
    }

/custom/wundergrounddev.json

{
  "title": "Weather Underground Dev",
  "author": "Joseph K. Goodman",
  "description": "Displays weather information from Weather Underground",
  "name": "wundergrounddev",
  "class": "Xibo\\Custom\\WundergroundDev\\WundergroundDev"
}

Is there a method by which I can uninstall the wundergrounddev module?

We don’t support uninstall at present - the best you can do is delete it from the module table manually, or set it’s status to disabled from the CMS Modules page.

Was this a typo? it should be located in /custom/WundergrounDev/

This is wrong - the class is Xibo\Custom\WundergroundDev\WundergroundDev as you had in your .json file

Thanks! That fixed it.

1 Like

Hello
I am installing a module and I will return “Invalid module”
How can I see what is the reason why it is invalid?

Thanks