DbExporter::write()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
nc 1
1
<?php namespace Nwidart\DbExporter;
2
3
use DB;
4
5
abstract class DbExporter
6
{
7
    /**
8
     * Contains the ignore tables
9
     * @var array $ignore
10
     */
11
    public static $ignore = array('migrations');
12
    public static $remote;
13
14
    /**
15
     * Get all the tables
16
     * @return mixed
17
     */
18
    protected function getTables()
19
    {
20
        $pdo = DB::connection()->getPdo();
21
        return $pdo->query('SELECT table_name FROM information_schema.tables WHERE table_schema="' . $this->database . '"');
22
    }
23
24
    public function getTableIndexes($table)
25
    {
26
        $pdo = DB::connection()->getPdo();
27
        return $pdo->query('SHOW INDEX FROM ' . $table . ' WHERE Key_name != "PRIMARY"');
28
    }
29
30
    /**
31
     * Get all the columns for a given table
32
     * @param $table
33
     * @return mixed
34
     */
35
    protected function getTableDescribes($table)
36
    {
37
        return DB::table('information_schema.columns')
38
            ->where('table_schema', '=', $this->database)
39
            ->where('table_name', '=', $table)
40
            ->get($this->selects);
41
    }
42
43
    /**
44
     * Grab all the table data
45
     * @param $table
46
     * @return mixed
47
     */
48
    protected function getTableData($table)
49
    {
50
        return DB::table($table)->get();
51
    }
52
53
    /**
54
     * Write the file
55
     * @return mixed
56
     */
57
    abstract public function write();
58
59
    /**
60
     * Convert the database to a usefull format
61
     * @param null $database
62
     * @return mixed
63
     */
64
    abstract public function convert($database = null);
65
66
    /**
67
     * Put the converted stub into a template
68
     * @return mixed
69
     */
70
    abstract protected function compile();
71
}