Jump to content

Custom module can't be installed/uninstalled


valan
 Share

Recommended Posts

Newbie journey into PW continues... ))

Chronology of events:

(1) Modified Helloworld module to add hook that updates several fields, when page is planned to be saved (see appendix)

(2) Installed OK

(3) Module doesn't work as intended... (e.g. fields are not updated, but also no any errors) 

(4) Trying to uninstall module, but module link doesn't open from admin>modules - some session error appears.

(5) Physically replacing module file with updated one and trying to install - the following appears... 

TemplateFile: Duplicate entry 'Zeerqhooks' for key 'class' INSERT INTO modules SET class='Zeerqhooks', flags=3, data=''

(6) OK. physically removing module file. It disappears in admin>modules

(7) Placing module file on the same place. It appears in admin>modules, but error in p.5 repeats...

Please advice how to uninstall first, non-accessible module in order to install new one? And what's wrong with the code?

Thanks for any help!

Appendix: Zeerqhooks.module

<?php

class Zeerqhooks extends WireData implements Module {

    public static function getModuleInfo() {

        return array(
            'title' => 'ZEERQ Hooks',  
            'version' => 101, 
            'summary' => 'ZEERQ hooks module updates 5 fields when vehicle page is saved',
            'singular' => true, 
            'autoload' => true, 
            );
    }

    public function init() {
        $this->addHookAfter('Pages::saveReady', $this, 'updateFields'); 
    }

    public function updateFields($event) {

        $page = $event->object; 

        // don't update fields in any page other then vehicle
        if($page->template != 'vehicle') return;
        
        // update all 5 fields
        $page->vehicle_ui_category         = $page->parent->parent->parent->parent->parent;
        $page->vehicle_ui_type             = $page->parent->parent->parent->parent;
        $page->vehicle_ui_brand         = $page->parent->parent->parent;
        $page->vehicle_ui_model         = $page->parent->parent;
        $page->vehicle_ui_modification     = $page->parent;
    }
}
?>
 
Link to comment
Share on other sites

a. Looks ok except you get the page with the argument given to saveReady

$page = $event->arguments(0);

I often use a little trick to debug to find why it doesn't work. Enter

$page = $event->arguments(0);
echo $page->title;
exit();

In the hook function, if the hook works you should see a white screen and the page title.

b. Remove the trailing ?> at the end, not needed and could give header already sent errors.

c. Other than that I can't produce the session error (what was it exactly?) Module works, install uninstall ...

Why do you wanted to uninstall the module? To change something in modules you usually don't have to uninstall it, except if you change stuff that would need to have it installed from scratch.

If you run into problems with a module, you should remove files AND the entry in the DB table "modules" for the module. Then start again.

  • Like 2
Link to comment
Share on other sites

Hi Soma! As usual - thank you for valuable recommendations!

I found mistype (compared initial and new modules): module name started with lowercase "zeerqhooks". Changed it to "Zeerqhooks" in the db and removed trailing ?> - after that everything works as intended! Somehow I've missed in docs that filename should be 100% class name.

Also thanks for debug trick - it saves hours!

Link to comment
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
 Share

×
×
  • Create New...