Table::createExtras()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Webino (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino/WebinoDbDump/ for the canonical source repository
6
 * @copyright   Copyright (c) 2014-2017 Webino, s. r. o. (http://webino.sk)
7
 * @license     BSD-3-Clause
8
 */
9
10
namespace WebinoDbDump\Db\Dump\Platform\Mysql\Table;
11
12
use WebinoDbDump\Db\Dump\Platform\Mysql\Routine\Procedure;
13
use WebinoDbDump\Db\Dump\Table\AbstractTable;
14
15
/**
16
 * Mysql database dump utility platform table
17
 *
18
 * @author Peter Bačinský <[email protected]>
19
 */
20
class Table extends AbstractTable
21
{
22
    /**
23
     * @var string
24
     */
25
    protected $rawName;
26
27
    /**
28
     * @param string $name
29
     * @return $this
30
     */
31
    protected function setName($name)
32
    {
33
        $this->rawName = $name;
34
        $this->name    = $this->getPlatform()->quoteIdentifier($this->rawName);
35
36
        return $this;
37
    }
38
39
    /**
40
     * @return \Zend\Db\ResultSet\ResultSet
41
     */
42
    protected function showCreate()
43
    {
44
        return $this->adapter->executeQuery('SHOW CREATE TABLE ' . $this->name);
45
    }
46
47
    /**
48
     * @return \Zend\Db\ResultSet\ResultSet
49
     */
50
    protected function showColumns()
51
    {
52
        return $this->adapter->executeQuery('SHOW COLUMNS FROM ' . $this->name);
53
    }
54
55
    /**
56
     * @return \Zend\Db\ResultSet\ResultSet
57
     */
58
    protected function select()
59
    {
60
        return $this->adapter->executeQuery('SELECT * FROM ' . $this->name);
61
    }
62
63
    /**
64
     * @return Columns
65
     */
66
    protected function createColumns()
67
    {
68
        return new Columns($this->getPlatform());
69
    }
70
71
    /**
72
     * @return array[Triggers, Procedure]
0 ignored issues
show
Documentation introduced by
The doc-type array[Triggers, could not be parsed: Expected "]" at position 2, but found "Triggers". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
73
     */
74
    protected function createExtras()
75
    {
76
        return [
77
            new Triggers($this->rawName, $this->adapter),
78
            new Procedure($this->rawName, $this->adapter),
79
        ];
80
    }
81
82
    /**
83
     * @return string
84
     */
85
    protected function create()
86
    {
87
        $row = $this->showCreate()->current();
88
89
        $isView = isset($row['Create View']);
90
        $this->setView($isView);
91
92
        $dump = '';
93
94
        // drop
95
        $dump .= sprintf(
96
            'DROP %s IF EXISTS %s;' . PHP_EOL,
97
            $isView ? 'VIEW' : 'TABLE',
98
            $this->name
99
        );
100
101
        // create
102
        $dump .= $row[$isView ? 'Create View' : 'Create Table'] . ';' . PHP_EOL . PHP_EOL;
103
104
        return $dump;
105
    }
106
107
    /**
108
     * @return string
109
     */
110
    protected function startInsert()
111
    {
112
        return 'LOCK TABLES ' . $this->name . ' WRITE;' . PHP_EOL
113
               .'INSERT INTO ' . $this->name . ' VALUES' . PHP_EOL;
114
    }
115
116
    /**
117
     * @return string
118
     */
119
    protected function continueInsert()
120
    {
121
        return ',';
122
    }
123
124
    /**
125
     * @return string
126
     */
127
    protected function finishInsert()
128
    {
129
        return ';' . PHP_EOL . 'UNLOCK TABLES;' . PHP_EOL;
130
    }
131
}
132