ifsnop / mysqldump-php

PHP version of mysqldump cli that comes with MySQL
https://github.com/ifsnop/mysqldump-php
GNU General Public License v3.0
1.25k stars 300 forks source link

Exporting all triggers when using include-tables #270

Open juppwerner opened 1 year ago

juppwerner commented 1 year ago

Hello,

I have skip-triggers set to false. I am also using include-tables to only select some tables.

I expect to only get the triggers related to the included tables. But all triggers get exported.

I believe a fix could be:

public function getDatabaseStructureTriggers()
{
    // Listing all triggers from database
    if (false === $this->dumpSettings['skip-triggers']) {
        foreach ($this->dbHandler->query($this->typeAdapter->show_triggers($this->dbName)) as $row) {
            if(in_array($row['Table'], $this->dumpSettings['include-views']))
                array_push($this->triggers, $row['Trigger']);
        }
    }
    return;
}

Thank you.

Regards Joachim

ifsnop commented 2 months ago

Maybe change include-views for include-tables in your code and add a check to ignore include-tables if it is empty?

 // Listing all triggers from database
    if (false === $this->dumpSettings['skip-triggers']) {
        foreach ($this->dbHandler->query($this->typeAdapter->show_triggers($this->dbName)) as $row) {
           if ( 0 == count($this->dumpSettings['include-tables']) ) 
               array_push($this->triggers, $row['Trigger']);
           else
               if(in_array($row['Table'], $this->dumpSettings['include-tables']))
                    array_push($this->triggers, $row['Trigger']);
        }
    }