Example #1
0
    static function table($table)
    {
        if (self::$log === 0) {
            return $table;
        } else {
            $versTable = vers::versTable($table);
            $view = '_vers_' . self::$log . '_' . $table;
            if (!D()->{$view}) {
                // http://stackoverflow.com/questions/15310219/mysql-get-record-with-lowest-value-views-select-contains-a-subquery-in-the-fr
                $sql = '
				CREATE VIEW ' . $view . '
				AS
				SELECT
					m.*
				FROM
					' . $versTable . ' m
				WHERE 1
				  AND !m._vers_deleted
					AND m._vers_space = ' . self::$space . '
					AND m._vers_log < ' . self::$log . '
					AND NOT EXISTS (
						SELECT 1
						FROM ' . $versTable . ' mm
						WHERE 1
							AND mm._vers_space = ' . self::$space . '
							AND mm._vers_log < ' . self::$log . '
							AND mm._vers_log > m._vers_log
						';
                foreach (D()->{$table}->getPrimaries() as $Primary) {
                    $sql .= 'AND mm.' . $Primary . ' = m.' . $Primary . ' ';
                }
                $sql .= '
						LIMIT 1
					)' . '';
                D()->query($sql);
                D()->addTable($view);
                // for the cache
                register_shutdown_function(function () use($view) {
                    D()->query("DROP VIEW " . $view);
                    D()->removeTable($view);
                    // for the cache
                });
            }
            return $view;
        }
    }
Example #2
0
function backtoLog($pid, $log)
{
    //$generate = null;
    //$generate = function ($pid) use(&$generate, $log) {
    //	vers::setLog($log);
    $generate = null;
    $generate = function ($pid) use(&$generate) {
        $Cont = Page($pid);
        foreach ($Cont->Conts() as $SubCont) {
            // todo, select only conts and no pages
            $generate($SubCont->id);
        }
        if ($Cont->access() < 2) {
            return;
        }
        // access in the past!?
        vers::tableRollBackWhere('page', array('id' => $pid));
        //vers::tableRollBackWhere('page', array('basis' => $pid, 'type'=>'c')); // remove subpages not in this version, problem: changes access!
        vers::tableRollBackWhere('page_class', array('page_id' => $pid));
        vers::tableRollBackWhere('page_file', array('page_id' => $pid));
        vers::tableRollBackWhere('page_text', array('page_id' => $pid));
        vers::tableRollBackWhere('page_url', array('page_id' => $pid));
        vers::tableRollBackWhere('text', array('id' => $Cont->vs['title_id']));
        // todo: cached!
        foreach (D()->col("SELECT text_id FROM page_text WHERE page_id = " . $pid) as $text_id) {
            vers::tableRollBackWhere('text', array('id' => $text_id));
        }
        foreach (D()->col("SELECT file_id FROM page_file WHERE page_id = " . $pid) as $file_id) {
            vers::tableRollBackWhere('file', array('id' => $file_id));
        }
        // qg settings
        $basis = G()->SET['cms']['pages']->i;
        vers::qgSettingsRollBack($basis, $pid);
    };
    settingArray::$All = array();
    cms::$_Pages = array();
    // remove Page-Object-Cache
    vers::setLog($log);
    $generate($pid);
    vers::setLog(0);
    cms::$_Pages = array();
    // remove Page-Object-Cache
    settingArray::$All = array();
}