/usr/share/horde/ansel/migration/10_ansel_upgrade_computestylehashes.php is in php-horde-ansel 3.0.5+debian0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | <?php
/**
* Ensures that all known style definitions have a hash entry.
*
* Copyright 2010-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Michael J. Rubinsky <mrubinsk@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/gpl GPL
* @package Ansel
*/
class AnselUpgradeComputestylehashes extends Horde_Db_Migration_Base
{
public function up()
{
// Migrate existing data for share
$sql = 'SELECT attribute_style, share_id FROM ansel_shares';
$this->announce('Computing style hashes from ansel_shares.', 'cli.message');
$rows = $this->_connection->selectAll($sql);
$this->_ensureHashes($rows);
// Migrate existing data for shareng
$sql = 'SELECT attribute_style, share_id FROM ansel_sharesng';
$this->announce('Computing style hashes from ansel_sharesng.', 'cli.message');
$rows = $this->_connection->selectAll($sql);
$this->_ensureHashes($rows);
}
/**
* Downgrade, though all style information will be lost and reverted to
* 'ansel_default'.
*/
public function down()
{
// noop
}
protected function _ensureHashes($rows)
{
foreach ($rows as $row) {
$style = unserialize($row['attribute_style']);
if (!$style instanceof Ansel_Style) {
$this->announce('ERROR: Not a valid Ansel_Style object for gallery_id: ' . $row['share_id'] . ': ' . print_r($style, true));
continue;
}
try {
$this->_ensureHash($style->getHash());
} catch (Exception $e) {
$this->announce('ERROR: ' . $e->getMessage());
}
}
}
/**
* Ensure the style hash is recorded in the database.
*
* @param string $hash The hash to record.
*/
protected function _ensureHash($hash)
{
$query = 'SELECT COUNT(*) FROM ansel_hashes WHERE style_hash = ?';
$results = $this->_connection->selectValue($query, array($hash));
if (!$results) {
$this->_connection->insert('INSERT INTO ansel_hashes (style_hash) VALUES(?)', array($hash));
}
}
}
|