Skip to content

Commit

Permalink
Made the Handle field a simple configurable static::$handleField
Browse files Browse the repository at this point in the history
- Small scrutiziner fixes and fixed comma first lines in MySQL class
  • Loading branch information
hparadiz committed May 16, 2018
1 parent 180d3a6 commit ace6462
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
10 changes: 5 additions & 5 deletions classes/Divergence/IO/Database/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public static function getConnection($label=null)
static::config();

$config = array_merge([
'host' => 'localhost'
,'port' => 3306,
'host' => 'localhost',
'port' => 3306,
], static::$Config[$label]);

if ($config['socket']) {
Expand Down Expand Up @@ -296,9 +296,9 @@ public static function handleError($query = '', $queryLog = false, $errorHandler
$Handler = \Divergence\App::$whoops->popHandler();

$Handler->addDataTable("Query Information", [
'Query' => $query
,'Error' => $message
,'ErrorCode' => self::getConnection()->errorCode(),
'Query' => $query,
'Error' => $message,
'ErrorCode' => self::getConnection()->errorCode(),
]);

\Divergence\App::$whoops->pushHandler($Handler);
Expand Down
20 changes: 9 additions & 11 deletions classes/Divergence/Models/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class ActiveRecord
public static $defaultConditions = [];

public static $primaryKey = null;
public static $handleField = 'Handle';

// support subclassing
public static $rootClass = null;
Expand Down Expand Up @@ -274,7 +275,7 @@ public function getValue($name)
}
}
// default Handle to ID if not caught by fieldExists
elseif ($name == 'Handle') {
elseif ($name == static::$handleField) {
return $this->ID;
}
}
Expand Down Expand Up @@ -554,8 +555,8 @@ public static function getByContext($contextClass, $contextID, $options = [])

public static function getByHandle($handle)
{
if (static::fieldExists('Handle')) {
if ($Record = static::getByField('Handle', $handle)) {
if (static::fieldExists(static::$handleField)) {
if ($Record = static::getByField(static::$handleField, $handle)) {
return $Record;
}
}
Expand Down Expand Up @@ -834,7 +835,7 @@ public static function getUniqueHandle($text, $options = [])
{
// apply default options
$options = Util::prepareOptions($options, [
'handleField' => 'Handle',
'handleField' => static::$handleField,
'domainConstraints' => [],
'alwaysSuffix' => false,
'format' => '%s:%u',
Expand Down Expand Up @@ -867,16 +868,13 @@ public static function getUniqueHandle($text, $options = [])
return $handle;
}


// TODO: make the handleField
public static function generateRandomHandle($length = 32)
{
// apply default options
$options = Util::prepareOptions($options, [
'handleField' => 'Handle',
]);

do {
$handle = substr(md5(mt_rand(0, mt_getrandmax())), 0, $length);
} while (static::getByField($options['handleField'], $handle));
} while (static::getByField(static::$handleField, $handle));

return $handle;
}
Expand Down Expand Up @@ -1031,7 +1029,7 @@ public static function handleError($query = null, $queryLog = null, $parameters

// handle query error
if ($ErrorInfo[0] != '00000') {
self::handleError($query, $queryLog, $errorHandler);
self::handleError($query, $queryLog);
}

// clear buffer (required for the next query to work without running fetchAll first
Expand Down

0 comments on commit ace6462

Please sign in to comment.