Skip to content

Commit 3c97e76

Browse files
authored
Merge branch 'develop-v4' into fix/add-label-to-network
2 parents 0fa9924 + 5754564 commit 3c97e76

File tree

4 files changed

+69
-34
lines changed

4 files changed

+69
-34
lines changed

php/EE/Model/Base.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ abstract class Base {
1717
/**
1818
* @var string Primary key of current model
1919
*/
20-
protected static $primary_key;
20+
protected static $primary_key = 'id';
2121

2222
/**
2323
* @var string It will contain an array of all fields that are present in database in table
2424
*/
2525
protected $fields;
2626

27+
/**
28+
* @var bool Weather the model needs timestamp whenever it's updated
29+
*/
30+
protected static $needs_update_timestamp = false;
31+
2732
/**
2833
* Base constructor.
2934
*
@@ -161,13 +166,13 @@ public static function create( $columns = [] ) {
161166
* Returns all model with condition
162167
*
163168
* @param string|array $column Column to search in
164-
* @param string|int $value Value to match
169+
* @param string $value Value to match
165170
*
166171
* @throws \Exception
167172
*
168173
* @return array
169174
*/
170-
public static function where( $column, $value ) {
175+
public static function where( $column, $value='' ) {
171176
return static::many_array_to_model(
172177
EE::db()
173178
->table( static::$table )
@@ -240,11 +245,15 @@ public function __unset( $name ) {
240245
* @return bool Model saved successfully
241246
*/
242247
public function save() {
243-
$fields = array_merge(
244-
$this->fields, [
245-
'modified_on' => date( 'Y-m-d H:i:s' ),
246-
]
247-
);
248+
$fields = $this->fields;
249+
250+
if ( static::$needs_update_timestamp ) {
251+
$fields = array_merge(
252+
$fields, [
253+
'modified_on' => date( 'Y-m-d H:i:s' ),
254+
]
255+
);
256+
}
248257

249258
$primary_key_column = static::$primary_key;
250259

php/class-ee-db.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ private static function create_required_tables() {
118118
FOREIGN KEY (site_url) REFERENCES sites(site_url)
119119
);';
120120

121+
$query .= 'CREATE TABLE auth_users (
122+
id INTEGER,
123+
site_url VARCHAR NOT NULL,
124+
username VARCHAR NOT NULL,
125+
password VARCHAR NOT NULL,
126+
scope VARCHAR NOT NULL,
127+
PRIMARY KEY (id)
128+
);';
129+
121130
try {
122131
self::$pdo->exec( $query );
123132
} catch ( PDOException $exception ) {
@@ -187,6 +196,10 @@ private function common_retrieval_function() {
187196
* [ 'id', '<', 100 ],
188197
* [ 'name', 'ee' ]
189198
* ])
199+
* or where([
200+
* 'id' => 100,
201+
* 'name' => 'ee',
202+
* ])
190203
*
191204
* Supported operators are: '=', '<', '>', '<=', '>=', '==', '!=', '<>', 'like', 'in'
192205
*
@@ -201,8 +214,15 @@ public function where( ...$args ) {
201214
$conditions = [];
202215

203216
if ( 'array' === gettype( $args[0] ) ) {
204-
foreach ( $args[0] as $condition ) {
205-
$conditions[] = $this->get_where_fragment( $condition );
217+
if ( \EE\Utils\is_assoc( $args[0] ) ) {
218+
$condition_keys = array_keys( $args[0] );
219+
foreach ( $condition_keys as $key ) {
220+
$conditions[] = $this->get_where_fragment( [ $key, $args[0][ $key ] ] );
221+
}
222+
} else {
223+
foreach ( $args[0] as $condition ) {
224+
$conditions[] = $this->get_where_fragment( $condition );
225+
}
206226
}
207227
} else {
208228
$conditions[] = $this->get_where_fragment( $args );

php/class-ee.php

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
22

3-
use \EE\ExitException;
4-
use \EE\Dispatcher;
5-
use \EE\FileCache;
6-
use \EE\Process;
7-
use \EE\Utils;
3+
use EE\Dispatcher;
4+
use EE\ExitException;
5+
use EE\FileCache;
6+
use EE\Process;
7+
use EE\Utils;
88
use Mustangostang\Spyc;
99

1010
/**
@@ -919,20 +919,6 @@ public static function exec( $command, $echo_stdout = false, $echo_stderr = fals
919919
* @return int|ProcessRun The command exit status, or a ProcessRun instance
920920
*/
921921
public static function launch_self( $command, $args = array(), $assoc_args = array(), $exit_on_error = true, $return_detailed = false, $runtime_args = array() ) {
922-
$reused_runtime_args = array(
923-
'path',
924-
'url',
925-
'user',
926-
);
927-
928-
foreach ( $reused_runtime_args as $key ) {
929-
if ( isset( $runtime_args[ $key ] ) ) {
930-
$assoc_args[ $key ] = $runtime_args[ $key ];
931-
} elseif ( $value = self::get_runner()->config[ $key ] ) {
932-
$assoc_args[ $key ] = $value;
933-
}
934-
}
935-
936922
$php_bin = escapeshellarg( Utils\get_php_binary() );
937923

938924
$script_path = $GLOBALS['argv'][0];

php/utils.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
namespace EE\Utils;
66

7-
use \Composer\Semver\Comparator;
8-
use \Composer\Semver\Semver;
9-
use \EE;
10-
use \EE\Dispatcher;
11-
use \EE\Iterators\Transform;
7+
use Composer\Semver\Comparator;
8+
use Composer\Semver\Semver;
9+
use EE;
10+
use EE\Iterators\Transform;
1211

1312
const PHAR_STREAM_PREFIX = 'phar://';
1413

@@ -423,6 +422,27 @@ function make_progress_bar( $message, $count, $interval = 100 ) {
423422
return new \cli\progress\Bar( $message, $count, $interval );
424423
}
425424

425+
/**
426+
* Checks if an array is associative array
427+
*
428+
* @param array $arr array to check
429+
*
430+
* @return bool
431+
*/
432+
function is_assoc( $arr ) {
433+
434+
$is_assoc = false;
435+
436+
foreach ( $arr as $key => $value ) {
437+
if ( is_string( $key ) ) {
438+
$is_assoc = true;
439+
break;
440+
}
441+
}
442+
443+
return $is_assoc;
444+
}
445+
426446
function parse_url( $url ) {
427447
$url_parts = \parse_url( $url );
428448

0 commit comments

Comments
 (0)