Skip to content

Instantly share code, notes, and snippets.

@ain
Created November 7, 2012 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ain/4034980 to your computer and use it in GitHub Desktop.
Save ain/4034980 to your computer and use it in GitHub Desktop.
Symfony 1.4 Doctrine migration base class for checking against existance of the table/field
<?php
abstract class SafeDoctrineMigrationBase extends Doctrine_Migration_Base
{
public function hasField($table, $field)
{
$conn = Doctrine_Manager::connection();
$result = $conn->execute("SHOW COLUMNS FROM $table LIKE '$field'");
$fields = $result->fetchAll();
return !empty($fields);
}
public function hasTable($table)
{
$conn = Doctrine_Manager::connection();
try
{
$conn->execute("DESC $table");
}
catch (Exception $e)
{
return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment