Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neuer Hook bevor die alten Tabellen gelöscht werden #117

Closed
backbone87 opened this issue Sep 7, 2012 · 5 comments
Closed

Neuer Hook bevor die alten Tabellen gelöscht werden #117

backbone87 opened this issue Sep 7, 2012 · 5 comments

Comments

@backbone87
Copy link

Es wäre schön einen Hook zu haben, der ausgeführt wird, nachdem die temporäre Tabelle erstellt wurde und bevor die alte Tabelle gelöscht wird. Hier könnte man dann Daten die nicht synchronisiert werden sollen aus der alten Tabelle zurücksyncen.

Zum Beispiel Domainnamen in Root-Pages:

UPDATE tl_page_temp AS t
SET t.domain = (SELECT p1.domain FROM tl_page AS p1 WHERE p1.id = t.id)
WHERE t.id IN (SELECT p2.id FROM tl_page AS p2 WHERE p2.type = 'root')
@stefanheimes
Copy link
Member

Neuer Hook ist drinnen. Bevor die alten Tabellen gelöscht und die temporären umbenannt werden, wird SQL Code ausgeführt.

Es sollte beachtet werden das syncCto alle Tabellen mit einem Präfix synccto_temp_ versieht. Dementsprechend müsste dein SQL dann so aussehen:

UPDATE synccto_temp_tl_page AS t
SET t.domain = (SELECT p1.domain FROM tl_page AS p1 WHERE p1.id = t.id)
WHERE t.id IN (SELECT p2.id FROM tl_page AS p2 WHERE p2.type = 'root')

Config

$GLOBALS['TL_HOOKS']['syncDBUpdate_BeforeDrop'][] = array('syncCtoHooks', 'syncDBUpdate_BeforeDrop');

PHP File

class syncCtoHooks extends Backend
{
    /**
     * @param int $intClientID Id of current client
     * @param array $arrSyncTables List with all tables
     * @param array $arrSQL List with all querys
     * @return array 
     */
    public function syncDBUpdate_BeforeDrop($intClientID, $arrSyncTables, $arrSQL)
    {
        if(!is_array($arrSQL))
        {
            $arrSQL = array();
        }

        if(in_array('tl_page', $arrSyncTables))
        {
            $arrSQL[]['query'] = 'UPDATE synccto_temp_tl_page SET tstamp = 0 WHERE 1=1';
        }

        return $arrSQL;
    }
}

@andreasisaak
Copy link
Contributor

Der Name des Hooks lautet jetzt syncDBUpdateBeforeDrop

@kikmedia
Copy link

kikmedia commented Oct 9, 2012

Auch wenn das eigentlich kein Tool für jeden ist würde ich es sehr begrüßen, wenn das - analog zu den granularen Datei-Sync-Blacklists - im BE konfigurierbar wäre anstatt den Hook mit möglicherweise schlecht gefrickeltem SQL zu nutzen. Nice to have. Kann ich Euch motivieren?

@backbone87
Copy link
Author

Mit derzeitiger Implementierung funktionier folgendes um die URLs der Wurzelseiten im Sync-Ziel nicht zu überschreiben:

<?php

class DomainSyncCtoHook extends Backend {

    /**
     * @param int $intClientID Id of current client
     * @param array $arrSyncTables List with all tables
     * @param array $arrSQL List with all querys
     * @return array
     */
    public function syncDBUpdateBeforeDrop($intClientID, $arrSyncTables, $arrSQL) {
        $arrSQL = (array) $arrSQL;

        if(!in_array('tl_page', $arrSyncTables)) {
            return $arrSQL;
        }

        $arrSQL[]['query'] = '
            UPDATE synccto_temp_tl_page AS t
            SET t.dns = (SELECT p1.dns FROM tl_page AS p1 WHERE p1.id = t.id)
            WHERE t.id IN (SELECT p2.id FROM tl_page AS p2 WHERE p2.type = \'root\')
        ';

        return $arrSQL;
    }

}

@andreasisaak
Copy link
Contributor

@kikmedia

Zur Dokumentation sei gesagt dass das von dir beschrieben Verhalten in die Pro Version Einzug finden wird. Für Devs haben wir den Hook bereitgestellt, wer es schicker und granulaner im Backend haben will der kann in den nächsten Wochen die neue Version kaufen/testen oder sich von mir beschenken lassen. Wie du als frühe Betatesterin ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants