We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51074
    • 14 Posts
    Please, help how it is possible to remove not only record in migxdb table, but also the file of a image on the server? Because data from the database are removed, but files of images remain on the server.
    The image name is stored in the database: <field key="image" dbtype="varchar" precision="255" phptype="string" default="" />
    Can use Hook Snippets? or there are other ways? help to solve a problem!
      • 5430
      • 247 Posts
      I think you would need to create a custom MIGX processor for this purpose (see https://forums.modx.com/thread/86388/custom-migx-processors for the order in which MIGX looks for instructions).
        • 51074
        • 14 Posts
        Quote from: claytonk at May 23, 2016, 12:04 AM
        I think you would need to create a custom MIGX processor for this purpose (see https://forums.modx.com/thread/86388/custom-migx-processors for the order in which MIGX looks for instructions).
        I know about work of modx not so much.It of course is very difficult. What processor (migxdb) to use for removal?
          • 5430
          • 247 Posts
          By default, migxdb is probably using the processor at core/components/migx/processors/mgr/default/. You can copy the code for that processor, modify the code so that it takes the additional step of deleting your file, and then save it to your package folder at core/components/yourpackage/processors/mgr/default/.
            • 51074
            • 14 Posts
            Quote from: claytonk at May 24, 2016, 09:39 AM
            By default, migxdb is probably using the processor at core/components/migx/processors/mgr/default/. You can copy the code for that processor, modify the code so that it takes the additional step of deleting your file, and then save it to your package folder at core/components/yourpackage/processors/mgr/default/.

            What processor I haven't decided to use. I have tried this emptytrash (from core/components/migx/processors/mgr/default/) and I have created the file (emptytrash.php) to your package folder at core\components\mybooks\processors\mgr\default\emptytrash.php
            And when empty the trash I delete files from the server.

            <?php 
            $modx->addPackage('mybooks', MODX_BASE_PATH . 'core/components/mybooks/model/', 'modx_'); // correctly???
            
            $resources = $modx->getCollection('mybooks', array('deleted'=>1)); 
            foreach ($resources as $k => $res) { 
            
            //at me image isn't simple, Image+
            
            $json = $res->get('image'); 
            $data = json_decode($json, true); 
            $src = $data['sourceImg']['src'] ; 
            $sourceid = $data['sourceImg']['source'] ; 
            // Load up the mediaSource 
            $source = $modx->getObject('sources.modMediaSource', $sourceid); 
            $properties = $source->getProperties(); 
            $pathimage = $properties['basePath']['value'].$src; 
            $assets_path = str_replace('assets/', "", $pathimage); 
            $directory = $modx->getOption('assets_path',null,MODX_CORE_PATH).$assets_path; 
            
            // delete files
            if(is_file($directory)) { 
            unlink($directory); 
            } 
            } 
            include $modx->getOption('core_path') . 'components/migx/processors/mgr/default/emptytrash.php';


            So everything works, but whether such decision is right?
              • 4172
              • 5,888 Posts
              looking good. If it works, it works and is right.
              Maybe, you should also remove files, before remove.php is called.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 51074
                • 14 Posts
                Quote from: Bruno17 at May 26, 2016, 10:37 AM
                looking good. If it works, it works and is right.
                Maybe, you should also remove files, before remove.php is called.

                Thanks for the answer! I will try also remove.php!