We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24865
    • 289 Posts
    This topic might be in the wrong board, but as this thread concerns installing a package I find it most fitting here.

    I’m busy to update modSwiftMailer to the latest xPDO standards when it comes down to installing, updating and uninstalling. This is also meant as a small learning project and will later be applied to my huge (still) closed source components and others.

    The fun bit is the setup, of course. I’ve sort of figured out with the help of Quip and Gallery how it all comes together, and by analysing the xPDOTransport and xPDOFileTransport-er. Currently I’ve got a working example to test all functionality.

    <?php
    
    ob_start();
    switch ($options[xPDOTransport::PACKAGE_ACTION]) {
        case xPDOTransport::ACTION_INSTALL:
    		echo 'Install';
    		break;
        case xPDOTransport::ACTION_UPGRADE:
    		echo 'Upgrade';
    		break;
    	case xPDOTransport::ACTION_UNINSTALL:
    		echo 'Uninstall!';
    		break;
    }
    
    echo 'Variables: ';
    print_r(array_keys(get_defined_vars()));
    echo 'Objects: ';
    $vars = get_defined_vars();
    
    foreach($vars as $key => $var) {
    	if ($key == 'modx' || $key == 'package') {
    		continue;
    	}
    	
    	echo $key.'::'.print_r($var);
    }
    
    $modx->log(1, xPDOTransport::PACKAGE_ACTION.' '.ob_get_contents());
    
    return '<pre style="max-height: 300px; overflow: auto;">'.ob_get_contents().'<pre>';


    First, I’m collecting all output with ob_start as I want it on-screen all at one. Next I print ALL keys that are available to me with the dollar sign ("$"). Amoung many it, of course, includes $modx. I don’t want the entire output of $modx and $package on-screen since that’ll flood the browser in most cases.

    Now, I’ve got it working for the most part, but the uninstall action is never called. I get no output when installing which I’d expect to get. No logs or what ever. This would mean I can’t clean up after the component is installed, like deleting cache files, assets from the assets folder or even system settings (they might be linked to the namespace, not sure on that).

    So the main question is, how to I implement UNINSTALL functionality AND does anybody have some kind of example for me to study and perhaps even use/improve.

    Thanks in advance. smiley
      @MarkGHErnst

      Developer at Adwise Internetmarketing, the Netherlands.
      • 3749
      • 24,544 Posts
      Rather than the output buffer, I’d suggest just using $output .= ’message’. Then just put the $output variable in your log() call. You should also call setLogTarget() and setLogLevel() before the log() call.

      If you use the modPackageBuilder class, everything you install through it will be uninstalled automatically.

      The exception being stuff you can’t create there and need to do in the PHP resolver, which you do need to uninstall explicitly.

      You might look at the SPForm package build.transport.php and install.script.php filed on my GitHub page: https://github.com/BobRay/SPForm/tree/master/_build. SPForm performs some actions on Uninstall (and they work).

      You might also consider downloading the GetMyComponent package, which has examples of almost anything you’d want to do in a transport package and can be adapted to actually build your package. See the tutorial here: http://bobsguides.com/mycomponent-tutorial.html.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 24865
        • 289 Posts
        I’ll give it a go, thanks Bob! If anyone has any additions, feel free to share! smiley I’ll post the outcome shortly.
          @MarkGHErnst

          Developer at Adwise Internetmarketing, the Netherlands.
          • 24865
          • 289 Posts
          I think that’ll help Bob, thanks a bunch!
            @MarkGHErnst

            Developer at Adwise Internetmarketing, the Netherlands.