Skip to content
Snippets Groups Projects
class.migrater.php 2.03 KiB
Newer Older
  • Learn to ignore specific revisions
  • <?php
    /*********************************************************************
        class.migrater.php
    
        SQL database migrater. This provides the engine capable of rolling the
        database for an osTicket installation forward (and perhaps even
        backward) in time using a set of included migration scripts. Each script
        will roll the database between two database checkpoints. Where possible,
        the migrater will roll several checkpoint scripts into one to be applied
        together.
    
        Jared Hancock <jared@osticket.com>
        Copyright (c)  2006-2012 osTicket
        http://www.osticket.com
    
        Released under the GNU General Public License WITHOUT ANY WARRANTY.
        See LICENSE.TXT for details.
    
        vim: expandtab sw=4 ts=4 sts=4:
    **********************************************************************/
    
    class DatabaseMigrater {
    
    
    Peter Rotich's avatar
    Peter Rotich committed
        var $start;
        var $end;
        var $sqldir;
    
        function DatabaseMigrater($start, $end, $sqldir) {
           
            $this->start = $start;
            $this->end = $end;
    
            $this->sqldir = $sqldir;
    
    Peter Rotich's avatar
    Peter Rotich committed
           
    
    Peter Rotich's avatar
    Peter Rotich committed
        function getPatches($stop=null) {
    
            $start= $this->start;
            $stop = $stop?$stop:$this->end;
    
    
            $patches = array();
            while (true) {
    
    Peter Rotich's avatar
    Peter Rotich committed
                $next = glob($this->sqldir . substr($start, 0, 8)
    
                             . '-*.patch.sql');
                if (count($next) == 1) {
                    $patches[] = $next[0];
    
    Peter Rotich's avatar
    Peter Rotich committed
                    $start = substr(basename($next[0]), 9, 8);
                } elseif (count($next) == 0) {
    
                    # There are no patches leaving the current signature. We
                    # have to assume that we've applied all the available
                    # patches.
                    break;
                } else {
                    # Problem -- more than one patch exists from this snapshot.
                    # We probably need a graph approach to solve this.
                    break;
                }
    
    
    Peter Rotich's avatar
    Peter Rotich committed
                # Break if we've reached our target stop.
                if(!$start || !strncasecmp($start, $stop, 8))
    
    Peter Rotich's avatar
    Peter Rotich committed
    
    
            return $patches;
        }
    }
    
    Peter Rotich's avatar
    Peter Rotich committed
    ?>