Skip to content

Commit

Permalink
MFH: Use Horde_Db's blob features to improve Oracle compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Dec 16, 2015
1 parent 77fb8bc commit 71db26d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions ansel/docs/CHANGES
Expand Up @@ -2,6 +2,7 @@
v3.0.4-git
----------

[jan] Improve Oracle compatibility.
[mjr] Fix content-type for screen images to be compatible with some versions
of IE.

Expand Down
27 changes: 17 additions & 10 deletions ansel/lib/Faces/Base.php
Expand Up @@ -646,10 +646,14 @@ function saveSignature($image_id, $face_id)
return;
}
// save compressed signature
$sql = 'UPDATE ansel_faces SET face_signature = ? WHERE face_id = ?';
$params = array(new Horde_Db_Value_Binary(puzzle_compress_cvec($signature)), $face_id);
try {
$GLOBALS['ansel_db']->update($sql, $params);
$GLOBALS['ansel_db']->updateBlob(
'ansel_faces',
array('face_signature' => new Horde_Db_Value_Binary(
puzzle_compress_cvec($signature))
),
array('face_id = ?', $face_id)
);
} catch (Horde_Db_Exception $e) {
throw new Ansel_Exception($result);
}
Expand All @@ -658,15 +662,16 @@ function saveSignature($image_id, $face_id)
$word_len = $GLOBALS['conf']['faces']['search'];
$str_len = strlen($signature);
$GLOBALS['ansel_db']->delete('DELETE FROM ansel_faces_index WHERE face_id = ' . $face_id);
$q = 'INSERT INTO ansel_faces_index (face_id, index_position, index_part) VALUES (?, ?, ?)';
$q = 'INSERT INTO () VALUES (?, ?, ?)';
$c = $str_len - $word_len;
for ($i = 0; $i <= $c; $i++) {
$data = array(
$face_id,
$i,
new Horde_Db_Value_Binary(substr($signature, $i, $word_len)));
'face_id' => $face_id,
'index_position' => $i,
'index_part' => new Horde_Db_Value_Binary(substr($signature, $i, $word_len))
);
try {
$GLOBALS['ansel_db']->insert($q, $data);
$GLOBALS['ansel_db']->insertBlob('ansel_faces_index', $data);
} catch (Horde_Db_Exception $e) {
throw new Ansel_Exception($e);
}
Expand Down Expand Up @@ -773,7 +778,8 @@ public function getFaceById($face_id, $full = false)

if ($full && $GLOBALS['conf']['faces']['search'] &&
function_exists('puzzle_uncompress_cvec')) {
$face['face_signature'] = puzzle_uncompress_cvec($face['face_signature']);
$columns = $GLOBALS['ansel_db']->columns('ansel_faces');
$face['face_signature'] = puzzle_uncompress_cvec($columns['face_signature']->binaryToString($face['face_signature']));
}

if (empty($face['face_name'])) {
Expand Down Expand Up @@ -840,6 +846,7 @@ public function getSignatureMatches($signature, $face_id = 0, $from = 0, $count
));

try {
$columns = $GLOBALS['ansel_db']->columns('ansel_faces');
$faces = $GLOBALS['ansel_db']->selectAll($sql);
} catch (Horde_Db_Exception $e) {
throw new Ansel_Exception($e);
Expand All @@ -851,7 +858,7 @@ public function getSignatureMatches($signature, $face_id = 0, $from = 0, $count
foreach ($faces as &$face) {
$face['similarity'] = puzzle_vector_normalized_distance(
$signature,
puzzle_uncompress_cvec($face['face_signature']));
puzzle_uncompress_cvec($columns['face_signature']->binaryToString($face['face_signature'])));
}
uasort($faces, array($this, '_getSignatureMatches'));

Expand Down
4 changes: 3 additions & 1 deletion ansel/package.xml
Expand Up @@ -33,6 +33,7 @@
</stability>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [jan] Improve Oracle compatibility.
* [mjr] Fix content-type for screen images to be compatible with some versions of IE.
</notes>
<contents>
Expand Down Expand Up @@ -640,7 +641,7 @@
<package>
<name>Horde_Db</name>
<channel>pear.horde.org</channel>
<min>2.0.3</min>
<min>2.2.0</min>
<max>3.0.0alpha1</max>
<exclude>3.0.0alpha1</exclude>
</package>
Expand Down Expand Up @@ -1376,6 +1377,7 @@
<date>2015-07-31</date>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [jan] Improve Oracle compatibility.
* [mjr] Fix content-type for screen images to be compatible with some versions of IE.
</notes>
</release>
Expand Down

0 comments on commit 71db26d

Please sign in to comment.