@@ -9,7 +9,7 @@ public function __construct() {
99 self ::init_db ();
1010 }
1111 }
12-
12+
1313 public function __destruct () {
1414 self ::$ db ->close ();
1515 }
@@ -34,7 +34,7 @@ public static function init_db() {
3434 public static function create () {
3535 self ::$ db = new SQLite3 ( DB );
3636 $ query = "CREATE TABLE sites (
37- id INTEGER NOT NULL,
37+ id INTEGER NOT NULL,
3838 sitename VARCHAR,
3939 site_type VARCHAR,
4040 site_title VARCHAR,
@@ -56,19 +56,31 @@ public static function create() {
5656 wp_pass VARCHAR,
5757 email VARCHAR,
5858 php_version VARCHAR,
59- PRIMARY KEY (id),
59+ PRIMARY KEY (id),
6060 UNIQUE (sitename),
61- CHECK (is_enabled IN (0, 1)),
61+ CHECK (is_enabled IN (0, 1)),
6262 CHECK (is_ssl IN (0, 1))
6363 ); " ;
6464
65- self ::$ db ->exec ( $ query );
66-
67- $ query = "CREATE TABLE migrations (
65+ $ query .= "CREATE TABLE migrations (
6866 migration VARCHAR,
6967 timestamp DATETIME
7068 ); " ;
7169
70+ $ query .= "CREATE TABLE services (
71+ id INTEGER NOT NULL,
72+ sitename VARCHAR,
73+ phpmyadmin BOOLEAN DEFAULT 0,
74+ mailhog BOOLEAN DEFAULT 0,
75+ postfix BOOLEAN DEFAULT 0,
76+ phpredisadmin BOOLEAN DEFAULT 0,
77+ adminer BOOLEAN DEFAULT 0,
78+ anemometer BOOLEAN DEFAULT 0,
79+ debug BOOLEAN DEFAULT 0,
80+ PRIMARY KEY (id),
81+ FOREIGN KEY (id) REFERENCES sites(id)
82+ ); " ;
83+
7284 self ::$ db ->exec ( $ query );
7385 }
7486
@@ -79,7 +91,7 @@ public static function create() {
7991 *
8092 * @return bool
8193 */
82- public static function insert ( $ data , $ table_name= 'sites ' ) {
94+ public static function insert ( $ data , $ table_name = 'sites ' ) {
8395
8496 if ( empty ( self ::$ db ) ) {
8597 self ::init_db ();
@@ -109,7 +121,7 @@ public static function insert( $data, $table_name='sites' ) {
109121 *
110122 * @return array|bool
111123 */
112- public static function select ( $ columns = array (), $ where = array (), $ table_name= 'sites ' ) {
124+ public static function select ( $ columns = array (), $ where = array (), $ table_name = 'sites ' , $ limit = null ) {
113125
114126 if ( empty ( self ::$ db ) ) {
115127 self ::init_db ();
@@ -134,6 +146,10 @@ public static function select( $columns = array(), $where = array(), $table_name
134146 $ select_data_query .= " WHERE $ conditions " ;
135147 }
136148
149+ if ( ! empty ( $ limit ) ) {
150+ $ select_data_query .= " LIMIT $ limit " ;
151+ }
152+
137153 $ select_data_exec = self ::$ db ->query ( $ select_data_query );
138154 $ select_data = array ();
139155 if ( $ select_data_exec ) {
@@ -157,7 +173,7 @@ public static function select( $columns = array(), $where = array(), $table_name
157173 *
158174 * @return bool
159175 */
160- public static function update ( $ data , $ where , $ table_name= 'sites ' ) {
176+ public static function update ( $ data , $ where , $ table_name = 'sites ' ) {
161177 if ( empty ( self ::$ db ) ) {
162178 self ::init_db ();
163179 }
@@ -192,7 +208,7 @@ public static function update( $data, $where, $table_name='sites' ) {
192208 *
193209 * @return bool
194210 */
195- public static function delete ( $ where , $ table_name= 'sites ' ) {
211+ public static function delete ( $ where , $ table_name = 'sites ' ) {
196212
197213 $ conditions = array ();
198214 foreach ( $ where as $ key => $ value ) {
@@ -268,9 +284,10 @@ public static function get_migrations() {
268284 }
269285
270286 $ sites = self ::select ( [ 'migration ' ], [], 'migrations ' );
271- if ( empty ( $ sites ) ) {
287+ if ( empty ( $ sites ) ) {
272288 return [];
273289 }
290+
274291 return array_column ( $ sites , 'migration ' );
275292 }
276293}
0 commit comments