Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Database\Migrations;
4
 
5
use Illuminate\Database\ConnectionResolverInterface as Resolver;
6
 
7
class DatabaseMigrationRepository implements MigrationRepositoryInterface
8
{
9
    /**
10
     * The database connection resolver instance.
11
     *
12
     * @var \Illuminate\Database\ConnectionResolverInterface
13
     */
14
    protected $resolver;
15
 
16
    /**
17
     * The name of the migration table.
18
     *
19
     * @var string
20
     */
21
    protected $table;
22
 
23
    /**
24
     * The name of the database connection to use.
25
     *
26
     * @var string
27
     */
28
    protected $connection;
29
 
30
    /**
31
     * Create a new database migration repository instance.
32
     *
33
     * @param  \Illuminate\Database\ConnectionResolverInterface  $resolver
34
     * @param  string  $table
35
     * @return void
36
     */
37
    public function __construct(Resolver $resolver, $table)
38
    {
39
        $this->table = $table;
40
        $this->resolver = $resolver;
41
    }
42
 
43
    /**
44
     * Get the completed migrations.
45
     *
46
     * @return array
47
     */
48
    public function getRan()
49
    {
50
        return $this->table()
51
                ->orderBy('batch', 'asc')
52
                ->orderBy('migration', 'asc')
53
                ->pluck('migration')->all();
54
    }
55
 
56
    /**
57
     * Get the list of migrations.
58
     *
59
     * @param  int  $steps
60
     * @return array
61
     */
62
    public function getMigrations($steps)
63
    {
64
        $query = $this->table()->where('batch', '>=', '1');
65
 
66
        return $query->orderBy('batch', 'desc')
67
                     ->orderBy('migration', 'desc')
68
                     ->take($steps)->get()->all();
69
    }
70
 
71
    /**
72
     * Get the last migration batch.
73
     *
74
     * @return array
75
     */
76
    public function getLast()
77
    {
78
        $query = $this->table()->where('batch', $this->getLastBatchNumber());
79
 
80
        return $query->orderBy('migration', 'desc')->get()->all();
81
    }
82
 
83
    /**
84
     * Get the completed migrations with their batch numbers.
85
     *
86
     * @return array
87
     */
88
    public function getMigrationBatches()
89
    {
90
        return $this->table()
91
                ->orderBy('batch', 'asc')
92
                ->orderBy('migration', 'asc')
93
                ->pluck('batch', 'migration')->all();
94
    }
95
 
96
    /**
97
     * Log that a migration was run.
98
     *
99
     * @param  string  $file
100
     * @param  int  $batch
101
     * @return void
102
     */
103
    public function log($file, $batch)
104
    {
105
        $record = ['migration' => $file, 'batch' => $batch];
106
 
107
        $this->table()->insert($record);
108
    }
109
 
110
    /**
111
     * Remove a migration from the log.
112
     *
113
     * @param  object  $migration
114
     * @return void
115
     */
116
    public function delete($migration)
117
    {
118
        $this->table()->where('migration', $migration->migration)->delete();
119
    }
120
 
121
    /**
122
     * Get the next migration batch number.
123
     *
124
     * @return int
125
     */
126
    public function getNextBatchNumber()
127
    {
128
        return $this->getLastBatchNumber() + 1;
129
    }
130
 
131
    /**
132
     * Get the last migration batch number.
133
     *
134
     * @return int
135
     */
136
    public function getLastBatchNumber()
137
    {
138
        return $this->table()->max('batch');
139
    }
140
 
141
    /**
142
     * Create the migration repository data store.
143
     *
144
     * @return void
145
     */
146
    public function createRepository()
147
    {
148
        $schema = $this->getConnection()->getSchemaBuilder();
149
 
150
        $schema->create($this->table, function ($table) {
151
            // The migrations table is responsible for keeping track of which of the
152
            // migrations have actually run for the application. We'll create the
153
            // table to hold the migration file's path as well as the batch ID.
154
            $table->increments('id');
155
            $table->string('migration');
156
            $table->integer('batch');
157
        });
158
    }
159
 
160
    /**
161
     * Determine if the migration repository exists.
162
     *
163
     * @return bool
164
     */
165
    public function repositoryExists()
166
    {
167
        $schema = $this->getConnection()->getSchemaBuilder();
168
 
169
        return $schema->hasTable($this->table);
170
    }
171
 
172
    /**
173
     * Delete the migration repository data store.
174
     *
175
     * @return void
176
     */
177
    public function deleteRepository()
178
    {
179
        $schema = $this->getConnection()->getSchemaBuilder();
180
 
181
        $schema->drop($this->table);
182
    }
183
 
184
    /**
185
     * Get a query builder for the migration table.
186
     *
187
     * @return \Illuminate\Database\Query\Builder
188
     */
189
    protected function table()
190
    {
191
        return $this->getConnection()->table($this->table)->useWritePdo();
192
    }
193
 
194
    /**
195
     * Get the connection resolver instance.
196
     *
197
     * @return \Illuminate\Database\ConnectionResolverInterface
198
     */
199
    public function getConnectionResolver()
200
    {
201
        return $this->resolver;
202
    }
203
 
204
    /**
205
     * Resolve the database connection instance.
206
     *
207
     * @return \Illuminate\Database\Connection
208
     */
209
    public function getConnection()
210
    {
211
        return $this->resolver->connection($this->connection);
212
    }
213
 
214
    /**
215
     * Set the information source to gather data.
216
     *
217
     * @param  string  $name
218
     * @return void
219
     */
220
    public function setSource($name)
221
    {
222
        $this->connection = $name;
223
    }
224
}