PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/framework/core/zap/ZoneRedo.php

http://zoop.googlecode.com/
PHP | 101 lines | 32 code | 14 blank | 55 comment | 0 complexity | 2ec56c88601597222a67c70763b9c4ab MD5 | raw file
  1<?php
  2class ZoneRedo
  3{
  4	function subMigration($p, $s)
  5	{
  6		$version = $p[3];
  7		SqlBeginTransaction();
  8		$filename = Migration::filenameFromVersion($version);
  9		Migration::undo($filename, $version);
 10		Migration::apply($filename, $version);
 11		SqlCommitTransaction();
 12	}
 13	
 14	function subMigrations($p, $s)
 15	{
 16		SqlBeginTransaction();
 17		
 18		//	make sure the migrations table exists
 19		Migration::initDB();
 20		
 21		//	have it scan the migrations directory for all available migrations
 22		$versions = Migration::getAllMigrationNames();
 23		// print_r($versions);
 24		$flipped = array_flip($versions);
 25		
 26		//	query the db for applied migrations in reverse order
 27		$applied = Migration::getAllAppiedMigrationNames();
 28		// print_r($applied);
 29		
 30		print_r($versions);
 31		print_r($applied);
 32		
 33		//	undo all of the migrations
 34		foreach($applied as $key => $migration)
 35		{
 36			Migration::undo($flipped[$migration], $migration);
 37		}
 38		
 39		//	now, reapply all of them
 40		foreach($versions as $key => $migration)
 41		{
 42			Migration::apply($key, $migration);
 43		}
 44		
 45		SqlCommitTransaction();
 46		
 47		
 48		
 49		
 50		//	apply anything that hasn't been done yet, in the proper order
 51		// $unapplied = array_diff($versions, $applied);
 52		// print_r($unapplied);die();
 53		
 54		// foreach($unapplied as $key => $needsApplied)
 55		// {
 56		// 	Migration::apply($key, $needsApplied);
 57		// }
 58		
 59		/*
 60		//	make sure the migrations table exists
 61		$schema = SqlGetSchema();
 62		if(!$schema->tableExists('migrations'))
 63		{
 64			SqlAlterSchema("create table migrations (
 65						id serial primary key, 
 66						name text not null,
 67						applied int2 not null default 0)");
 68		}
 69		
 70		//	have it scan the migrations directory for all available migrations
 71		$filenames = ListDir(getcwd() . '/migrations', array('extentions' => array('php')));
 72		$versions = array();
 73		foreach($filenames as $thisFilename)
 74		{
 75			$parts = explode('_', $thisFilename);
 76			$version = $parts[0];
 77			$versions[$thisFilename] = $version;
 78		}
 79		
 80		//	query the db for applied migrations
 81		$applied = SqlFetchColumn("select name from migrations where applied = 1", array());
 82		
 83		//	apply anything that hasn't been done yet, in the proper order
 84		$unapplied = array_diff($versions, $applied);
 85		print_r($unapplied);
 86		foreach($unapplied as $key => $needsApplied)
 87		{
 88			//	apply the migration
 89			include_once(getcwd() . '/migrations/' . $key);
 90			$className = 'Migration_' . str_replace('.', '_', $needsApplied);
 91			$migration = new $className();
 92			$migration->up();
 93			
 94			//	mark it as applied
 95			SqlUpsertRow('migrations', array('name' => $needsApplied), array('applied' => 1));
 96			
 97			print_r($migration);
 98		}
 99		*/
100	}
101}