Code Duplication    Length = 26-26 lines in 2 locations

src/LocalChangesTracker.php 2 locations

@@ 118-143 (lines=26) @@
115
        $this->connection->exec($sql);
116
    }
117
118
    public function createInsertTrigger(Table $table)
119
    {
120
        $triggerName = sprintf('TRG_%s_ONINSERT', $table->getName());
121
        $this->logger->info('Creating ' . $triggerName . ' trigger for table ' . $table->getName() . '...');
122
123
        $tableNameQuoted = $this->connection->quote($table->getName());
124
125
        $sql = sprintf(
126
            '
127
            DROP TRIGGER IF EXISTS %s;
128
            
129
            CREATE TRIGGER %s AFTER INSERT ON `%s` 
130
            FOR EACH ROW
131
            BEGIN
132
              IF (NEW.id IS NULL AND NEW.createdTime IS NULL ) THEN
133
                INSERT INTO local_insert VALUES (%s, NEW.uid);
134
                DELETE FROM local_delete WHERE table_name = %s AND uid = NEW.uid;
135
                DELETE FROM local_update WHERE table_name = %s AND uid = NEW.uid;
136
              END IF;
137
            END;
138
            
139
            ', $triggerName, $triggerName, $table->getName(), $tableNameQuoted, $tableNameQuoted, $tableNameQuoted
140
        );
141
142
        $this->connection->exec($sql);
143
    }
144
145
    public function createDeleteTrigger(Table $table)
146
    {
@@ 145-170 (lines=26) @@
142
        $this->connection->exec($sql);
143
    }
144
145
    public function createDeleteTrigger(Table $table)
146
    {
147
        $triggerName = sprintf('TRG_%s_ONDELETE', $table->getName());
148
        $this->logger->info('Creating ' . $triggerName . ' trigger for table ' . $table->getName() . '...');
149
150
        $tableNameQuoted = $this->connection->quote($table->getName());
151
152
        $sql = sprintf(
153
            '
154
            DROP TRIGGER IF EXISTS %s;
155
            
156
            CREATE TRIGGER %s BEFORE DELETE ON `%s` 
157
            FOR EACH ROW
158
            BEGIN
159
              IF (OLD.id IS NOT NULL) THEN
160
                INSERT INTO local_delete VALUES (%s, OLD.uid, OLD.id);
161
              END IF;
162
              DELETE FROM local_insert WHERE table_name = %s AND uid = OLD.uid;
163
              DELETE FROM local_update WHERE table_name = %s AND uid = OLD.uid;
164
            END;
165
            
166
            ', $triggerName, $triggerName, $table->getName(), $tableNameQuoted, $tableNameQuoted, $tableNameQuoted
167
        );
168
169
        $this->connection->exec($sql);
170
    }
171
172
    public function createUpdateTrigger(Table $table)
173
    {