Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/*
3
 *  $Id: Process.php 1080 2007-02-10 18:17:08Z jwage $
4
 *
5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
 *
17
 * This software consists of voluntary contributions made by many individuals
18
 * and is licensed under the LGPL. For more information, see
19
 * <http://www.doctrine-project.org>.
20
 */
21
 
22
/**
23
 * Doctrine_Migration_Process
24
 *
25
 * @package     Doctrine
26
 * @subpackage  Migration
27
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
28
 * @link        www.doctrine-project.org
29
 * @since       1.0
30
 * @version     $Revision: 1080 $
31
 * @author      Jonathan H. Wage <jwage@mac.com>
32
 */
33
class Doctrine_Migration_Process
34
{
35
    protected
36
        $_migration;
37
 
38
    public function __construct(Doctrine_Migration $migration)
39
    {
40
        $this->_migration = $migration;
41
    }
42
 
43
    public function getConnection()
44
    {
45
        return $this->_migration->getConnection();
46
    }
47
 
48
    /**
49
     * Process a created table change
50
     *
51
     * @param string $table Table definition
52
     * @return void
53
     */
54
    public function processCreatedTable(array $table)
55
    {
56
        $this->getConnection()->export->createTable($table['tableName'], $table['fields'], $table['options']);
57
    }
58
 
59
    /**
60
     * Process a dropped table change
61
     *
62
     * @param array $table Table definition
63
     * @return void
64
     */
65
    public function processDroppedTable(array $table)
66
    {
67
        $this->getConnection()->export->dropTable($table['tableName']);
68
    }
69
 
70
    /**
71
     * Process a renamed table change
72
     *
73
     * @param array $table Renamed table definition
74
     * @return void
75
     */
76
    public function processRenamedTable(array $table)
77
    {
78
        $this->getConnection()->export->alterTable($table['oldTableName'], array('name' => $table['newTableName']));
79
    }
80
 
81
    /**
82
     * Process a created column change
83
     *
84
     * @param array $column Column definition
85
     * @return void
86
     */
87
    public function processCreatedColumn(array $column)
88
    {
89
        $this->getConnection()->export->alterTable($column['tableName'], array('add' => array($column['columnName'] => $column)));
90
    }
91
 
92
    /**
93
     * Process a dropped column change
94
     *
95
     * @param array $column Column definition
96
     * @return void
97
     */
98
    public function processDroppedColumn(array $column)
99
    {
100
        $this->getConnection()->export->alterTable($column['tableName'], array('remove' => array($column['columnName'] => array())));
101
    }
102
 
103
    /**
104
     * Process a renamed column change
105
     *
106
     * @param array $column Column definition
107
     * @return void
108
     */
109
    public function processRenamedColumn(array $column)
110
    {
111
        $columnList = $this->getConnection()->import->listTableColumns($column['tableName']);
112
        if (isset($columnList[$column['oldColumnName']])) {
113
            $this->getConnection()->export->alterTable($column['tableName'], array('rename' => array($column['oldColumnName'] => array('name' => $column['newColumnName'], 'definition' => $columnList[$column['oldColumnName']]))));
114
        }
115
    }
116
 
117
    /**
118
     * Process a changed column change
119
     *
120
     * @param array $column Changed column definition
121
     * @return void
122
     */
123
    public function processChangedColumn(array $column)
124
    {
125
        $options = array();
126
        $options = $column['options'];
127
        $options['type'] = $column['type'];
128
 
129
        $this->getConnection()->export->alterTable($column['tableName'], array('change' => array($column['columnName'] => array('definition' => $options))));
130
    }
131
 
132
    /**
133
     * Process a created index change
134
     *
135
     * @param array $index Index definition
136
     * @return void
137
     */
138
    public function processCreatedIndex(array $index)
139
    {
140
        $this->getConnection()->export->createIndex($index['tableName'], $index['indexName'], $index['definition']);
141
    }
142
 
143
    /**
144
     * Process a dropped index change
145
     *
146
     * @param array $index Index definition
147
     * @return void
148
     */
149
    public function processDroppedIndex(array $index)
150
    {
151
        $this->getConnection()->export->dropIndex($index['tableName'], $index['indexName']);
152
    }
153
 
154
    /**
155
     * Process a created constraint change
156
     *
157
     * @param array $constraint Constraint definition
158
     * @return void
159
     */
160
    public function processCreatedConstraint(array $constraint)
161
    {
162
        $this->getConnection()->export->createConstraint($constraint['tableName'], $constraint['constraintName'], $constraint['definition']);
163
    }
164
 
165
    /**
166
     * Process a dropped constraint change
167
     *
168
     * @param array $constraint Constraint definition
169
     * @return void
170
     */
171
    public function processDroppedConstraint(array $constraint)
172
    {
173
        $this->getConnection()->export->dropConstraint($constraint['tableName'], $constraint['constraintName'], isset($constraint['definition']['primary']) && $constraint['definition']['primary']);
174
    }
175
 
176
    /**
177
     * Process a created foreign key change
178
     *
179
     * @param array $foreignKey Foreign key definition
180
     * @return void
181
     */
182
    public function processCreatedForeignKey(array $foreignKey)
183
    {
184
        $this->getConnection()->export->createForeignKey($foreignKey['tableName'], $foreignKey['definition']);
185
    }
186
 
187
    /**
188
     * Process a dropped foreign key change
189
     *
190
     * @param array $foreignKey
191
     * @return void
192
     */
193
    public function processDroppedForeignKey(array $foreignKey)
194
    {
195
        $this->getConnection()->export->dropForeignKey($foreignKey['tableName'], $foreignKey['definition']['name']);
196
    }
197
}