mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-26 03:13:12 +00:00
@@ -10,18 +10,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use Alchemy\Phrasea\Application;
|
use Alchemy\Phrasea\Application;
|
||||||
use Alchemy\Phrasea\SearchEngine\Elastic\RecordHelper;
|
use MediaAlchemyst\Exception\ExceptionInterface;
|
||||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||||
use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
||||||
use MediaAlchemyst\Specification\Image as ImageSpecification;
|
use MediaAlchemyst\Specification\Image as ImageSpecification;
|
||||||
use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
use Symfony\Component\HttpFoundation\File\Exception\FileException;
|
||||||
use Alchemy\Phrasea\Model\RecordInterface;
|
|
||||||
|
|
||||||
class databox_status
|
class databox_status
|
||||||
{
|
{
|
||||||
public static function getSearchStatus(Application $app)
|
public static function getSearchStatus(Application $app)
|
||||||
{
|
{
|
||||||
$structures = $stats = [];
|
$structures = [];
|
||||||
foreach ($app->getAclForUser($app->getAuthenticatedUser())->get_granted_sbas() as $databox) {
|
foreach ($app->getAclForUser($app->getAuthenticatedUser())->get_granted_sbas() as $databox) {
|
||||||
$see_all = false;
|
$see_all = false;
|
||||||
foreach ($databox->get_collections() as $collection) {
|
foreach ($databox->get_collections() as $collection) {
|
||||||
@@ -131,7 +130,7 @@ class databox_status
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$app['media-alchemyst']->turninto($filePath, $destPath, $imageSpec);
|
$app['media-alchemyst']->turninto($filePath, $destPath, $imageSpec);
|
||||||
} catch (\MediaAlchemyst\Exception $e) {
|
} catch (ExceptionInterface $e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,8 +148,9 @@ class databox_status
|
|||||||
if (substr($stat2, 0, 2) === '0x') {
|
if (substr($stat2, 0, 2) === '0x') {
|
||||||
$stat2 = self::hex2bin(substr($stat2, 2));
|
$stat2 = self::hex2bin(substr($stat2, 2));
|
||||||
}
|
}
|
||||||
|
$length = max(strlen($stat1), strlen($stat2));
|
||||||
|
|
||||||
return dechex(hexdec($stat1) & hexdec($stat2));
|
return str_pad(decbin(bindec($stat1) & bindec($stat2)), $length, '0', STR_PAD_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -164,6 +164,8 @@ class databox_status
|
|||||||
*/
|
*/
|
||||||
public static function operation_mask($stat1, $stat2)
|
public static function operation_mask($stat1, $stat2)
|
||||||
{
|
{
|
||||||
|
$length = max(strlen($stat1), strlen($stat2));
|
||||||
|
|
||||||
$stat1 = str_pad($stat1, 32, '0', STR_PAD_LEFT);
|
$stat1 = str_pad($stat1, 32, '0', STR_PAD_LEFT);
|
||||||
$stat2 = str_pad($stat2, 32, '0', STR_PAD_LEFT);
|
$stat2 = str_pad($stat2, 32, '0', STR_PAD_LEFT);
|
||||||
$stat1_or = bindec(trim(str_replace("x", "0", $stat1)));
|
$stat1_or = bindec(trim(str_replace("x", "0", $stat1)));
|
||||||
@@ -171,7 +173,9 @@ class databox_status
|
|||||||
$stat2_or = bindec(trim(str_replace("x", "0", $stat2)));
|
$stat2_or = bindec(trim(str_replace("x", "0", $stat2)));
|
||||||
$stat2_and = bindec(trim(str_replace("x", "1", $stat2)));
|
$stat2_and = bindec(trim(str_replace("x", "1", $stat2)));
|
||||||
|
|
||||||
return decbin((((0 | $stat1_or) & $stat1_and) | $stat2_or) & $stat2_and);
|
$decbin = decbin((((0 | $stat1_or) & $stat1_and) | $stat2_or) & $stat2_and);
|
||||||
|
|
||||||
|
return str_pad($decbin, $length, '0', STR_PAD_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function operation_and_not($stat1, $stat2)
|
public static function operation_and_not($stat1, $stat2)
|
||||||
@@ -182,10 +186,12 @@ class databox_status
|
|||||||
if (substr($stat2, 0, 2) === '0x') {
|
if (substr($stat2, 0, 2) === '0x') {
|
||||||
$stat2 = self::hex2bin(substr($stat2, 2));
|
$stat2 = self::hex2bin(substr($stat2, 2));
|
||||||
}
|
}
|
||||||
|
$length = max(strlen($stat1), strlen($stat2));
|
||||||
|
|
||||||
$stat1 = str_pad($stat1, 32, '0', STR_PAD_LEFT);
|
$stat1 = str_pad($stat1, 32, '0', STR_PAD_LEFT);
|
||||||
$stat2 = str_pad($stat2, 32, '0', STR_PAD_LEFT);
|
$stat2 = str_pad($stat2, 32, '0', STR_PAD_LEFT);
|
||||||
|
|
||||||
return decbin(bindec($stat1) & ~bindec($stat2));
|
return str_pad(decbin(bindec($stat1) & ~bindec($stat2)), $length, '0', STR_PAD_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function operation_or($stat1, $stat2)
|
public static function operation_or($stat1, $stat2)
|
||||||
@@ -196,10 +202,11 @@ class databox_status
|
|||||||
if (substr($stat2, 0, 2) === '0x') {
|
if (substr($stat2, 0, 2) === '0x') {
|
||||||
$stat2 = self::hex2bin(substr($stat2, 2));
|
$stat2 = self::hex2bin(substr($stat2, 2));
|
||||||
}
|
}
|
||||||
|
$length = max(strlen($stat1), strlen($stat2));
|
||||||
$stat1 = str_pad($stat1, 32, '0', STR_PAD_LEFT);
|
$stat1 = str_pad($stat1, 32, '0', STR_PAD_LEFT);
|
||||||
$stat2 = str_pad($stat2, 32, '0', STR_PAD_LEFT);
|
$stat2 = str_pad($stat2, 32, '0', STR_PAD_LEFT);
|
||||||
|
|
||||||
return decbin(bindec($stat1) | bindec($stat2));
|
return str_pad(decbin(bindec($stat1) | bindec($stat2)), $length, '0', STR_PAD_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function dec2bin($status)
|
public static function dec2bin($status)
|
||||||
@@ -224,7 +231,7 @@ class databox_status
|
|||||||
throw new \Exception('Non-hexadecimal value');
|
throw new \Exception('Non-hexadecimal value');
|
||||||
}
|
}
|
||||||
|
|
||||||
return base_convert($status, 16, 2);
|
return str_pad(base_convert($status, 16, 2), 4*strlen($status), '0', STR_PAD_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function bitIsSet($bitValue, $nthBit)
|
public static function bitIsSet($bitValue, $nthBit)
|
||||||
|
|||||||
@@ -1163,25 +1163,6 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
['status' => bindec($status), 'record_id' => $this->record_id]
|
['status' => bindec($status), 'record_id' => $this->record_id]
|
||||||
);
|
);
|
||||||
|
|
||||||
$status = strrev($status);
|
|
||||||
$length = strlen($status);
|
|
||||||
$sqlValues = [];
|
|
||||||
for ($i = 4; $i < $length; $i++) {
|
|
||||||
$sqlValues[] = join(',', array(
|
|
||||||
'null',
|
|
||||||
$connection->quote($this->getRecordId()),
|
|
||||||
$connection->quote($i),
|
|
||||||
$connection->quote($status[$i])
|
|
||||||
));
|
|
||||||
}
|
|
||||||
$sql = "REPLACE INTO status (id, record_id, name, value)"
|
|
||||||
. " VALUES (" . join('),(', $sqlValues) . ")";
|
|
||||||
$stmt = $connection->prepare($sql);
|
|
||||||
|
|
||||||
$stmt->execute();
|
|
||||||
|
|
||||||
$stmt->closeCursor();
|
|
||||||
|
|
||||||
$this->delete_data_from_cache(self::CACHE_STATUS);
|
$this->delete_data_from_cache(self::CACHE_STATUS);
|
||||||
|
|
||||||
$this->dispatch(RecordEvents::STATUS_CHANGED, new StatusChangedEvent($this));
|
$this->dispatch(RecordEvents::STATUS_CHANGED, new StatusChangedEvent($this));
|
||||||
|
|||||||
@@ -2447,74 +2447,6 @@
|
|||||||
</indexes>
|
</indexes>
|
||||||
<engine>InnoDB</engine>
|
<engine>InnoDB</engine>
|
||||||
</table>
|
</table>
|
||||||
<table name="status">
|
|
||||||
<fields>
|
|
||||||
<field>
|
|
||||||
<name>id</name>
|
|
||||||
<type>int(10) unsigned</type>
|
|
||||||
<null></null>
|
|
||||||
<extra>auto_increment</extra>
|
|
||||||
<default></default>
|
|
||||||
<comment></comment>
|
|
||||||
</field>
|
|
||||||
<field>
|
|
||||||
<name>record_id</name>
|
|
||||||
<type>int(11) unsigned</type>
|
|
||||||
<null></null>
|
|
||||||
<extra></extra>
|
|
||||||
<default>0</default>
|
|
||||||
<comment></comment>
|
|
||||||
</field>
|
|
||||||
<field>
|
|
||||||
<name>name</name>
|
|
||||||
<type>int(2) unsigned</type>
|
|
||||||
<null></null>
|
|
||||||
<extra></extra>
|
|
||||||
<default></default>
|
|
||||||
<comment></comment>
|
|
||||||
</field>
|
|
||||||
<field>
|
|
||||||
<name>value</name>
|
|
||||||
<type>tinyint(1) unsigned</type>
|
|
||||||
<null></null>
|
|
||||||
<extra></extra>
|
|
||||||
<default></default>
|
|
||||||
<comment></comment>
|
|
||||||
</field>
|
|
||||||
</fields>
|
|
||||||
<indexes>
|
|
||||||
<index>
|
|
||||||
<name>PRIMARY</name>
|
|
||||||
<type>PRIMARY</type>
|
|
||||||
<fields>
|
|
||||||
<field>id</field>
|
|
||||||
</fields>
|
|
||||||
</index>
|
|
||||||
<index>
|
|
||||||
<name>value</name>
|
|
||||||
<type>INDEX</type>
|
|
||||||
<fields>
|
|
||||||
<field>value</field>
|
|
||||||
</fields>
|
|
||||||
</index>
|
|
||||||
<index>
|
|
||||||
<name>record_id</name>
|
|
||||||
<type>INDEX</type>
|
|
||||||
<fields>
|
|
||||||
<field>record_id</field>
|
|
||||||
</fields>
|
|
||||||
</index>
|
|
||||||
<index>
|
|
||||||
<name>unique</name>
|
|
||||||
<type>UNIQUE</type>
|
|
||||||
<fields>
|
|
||||||
<field>record_id</field>
|
|
||||||
<field>name</field>
|
|
||||||
</fields>
|
|
||||||
</index>
|
|
||||||
</indexes>
|
|
||||||
<engine>InnoDB</engine>
|
|
||||||
</table>
|
|
||||||
<table name="idx">
|
<table name="idx">
|
||||||
<fields>
|
<fields>
|
||||||
<field>
|
<field>
|
||||||
|
|||||||
@@ -4,49 +4,49 @@ class databox_statusTest extends PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
public function testOperation_and()
|
public function testOperation_and()
|
||||||
{
|
{
|
||||||
$this->assertEquals('0', databox_status::operation_and('0x001', '0x010'));
|
$this->assertSame('000000000000', databox_status::operation_and('0x001', '0x010'));
|
||||||
$this->assertEquals('1', databox_status::operation_and('01', '11'));
|
$this->assertSame('01', databox_status::operation_and('01', '11'));
|
||||||
$this->assertEquals('0', databox_status::operation_and('01', '10'));
|
$this->assertSame('00', databox_status::operation_and('01', '10'));
|
||||||
$this->assertEquals('10', databox_status::operation_and('11', '10'));
|
$this->assertSame('10', databox_status::operation_and('11', '10'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOperation_and_not()
|
public function testOperation_and_not()
|
||||||
{
|
{
|
||||||
$this->assertEquals('0', databox_status::operation_and_not('0x001', '0x011'));
|
$this->assertSame('000000000000', databox_status::operation_and_not('0x001', '0x011'));
|
||||||
$this->assertEquals('0', databox_status::operation_and_not('01', '11'));
|
$this->assertSame('00', databox_status::operation_and_not('01', '11'));
|
||||||
$this->assertEquals('1', databox_status::operation_and_not('01', '10'));
|
$this->assertSame('01', databox_status::operation_and_not('01', '10'));
|
||||||
$this->assertEquals('1', databox_status::operation_and_not('11', '10'));
|
$this->assertSame('01', databox_status::operation_and_not('11', '10'));
|
||||||
$this->assertEquals('10', databox_status::operation_and_not('10', '01'));
|
$this->assertSame('10', databox_status::operation_and_not('10', '01'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOperation_mask()
|
public function testOperation_mask()
|
||||||
{
|
{
|
||||||
$this->assertEquals('001101', databox_status::operation_mask('010101', '0011xx'));
|
$this->assertSame('001101', databox_status::operation_mask('010101', '0011xx'));
|
||||||
$this->assertEquals('001100', databox_status::operation_mask('0', '0011xx'));
|
$this->assertSame('001100', databox_status::operation_mask('0', '0011xx'));
|
||||||
$this->assertEquals('001101', databox_status::operation_mask('1', '0011xx'));
|
$this->assertSame('001101', databox_status::operation_mask('1', '0011xx'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testOperation_or()
|
public function testOperation_or()
|
||||||
{
|
{
|
||||||
$this->assertEquals('10001', databox_status::operation_or('0x001', '0x011'));
|
$this->assertSame('000000010001', databox_status::operation_or('0x001', '0x011'));
|
||||||
$this->assertEquals('11', databox_status::operation_or('01', '11'));
|
$this->assertSame('11', databox_status::operation_or('01', '11'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDec2bin()
|
public function testDec2bin()
|
||||||
{
|
{
|
||||||
$this->assertEquals('1010', databox_status::dec2bin('10'));
|
$this->assertSame('1010', databox_status::dec2bin('10'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHex2bin()
|
public function testHex2bin()
|
||||||
{
|
{
|
||||||
$this->assertEquals('10100001', databox_status::hex2bin('0x0A1'));
|
$this->assertSame('000010100001', databox_status::hex2bin('0x0A1'));
|
||||||
$this->assertEquals('10100001', databox_status::hex2bin('0A1'));
|
$this->assertSame('000010100001', databox_status::hex2bin('0A1'));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
databox_status::hex2bin('G1');
|
databox_status::hex2bin('G1');
|
||||||
$this->fail('Should raise an exception');
|
$this->fail('Should raise an exception');
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->assertEquals('Non-hexadecimal value', $e->getMessage());
|
$this->assertSame('Non-hexadecimal value', $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user