1206
1289
/* 2.0 Release! */
1293
/* Schema only upgrade */
1294
$ret = $storage->configureStore($module->getId(),
1295
array('GalleryPluginParameterMap:1.2'));
1297
return $ret->wrap(__FILE__, __LINE__);
1301
/* And image/wmf mime type */
1302
list ($ret, $mimeType) = GalleryCoreApi::convertExtensionToMime('wmf');
1303
if (!$ret && $mimeType == 'application/unknown') {
1304
$ret = GalleryCoreApi::addMimeType('wmf', 'image/wmf', false);
1306
return $ret->wrap(__FILE__, __LINE__);
1209
1311
/* Security fix */
1314
/* Consolidated .sql files into schema.tpl */
1317
/* Added maintenance mode */
1320
/* Remove plugins directory from g2data. */
1321
$pluginDirectory = $gallery->getConfig('data.gallery.base') . 'plugins';
1322
$pluginDirectories = array($pluginDirectory . '/modules',
1323
$pluginDirectory . '/themes',
1326
foreach ($pluginDirectories as $pluginDirectory) {
1327
if (@$platform->file_exists($pluginDirectory)) {
1328
/* We're not interested in whether it succeeded or not. */
1329
@$platform->recursiveRmDir($pluginDirectory);
1334
/* Add PluginPackageMap table */
1337
$ret = $module->setParameter('exec.beNice', '0');
1339
return $ret->wrap(__FILE__, __LINE__);
1212
1344
/* Security fix in zipcart */
1347
/* Rename unnamed pre-beta-3 index to named index */
1348
if ($storage->getType() == 'mysql') {
1349
$gallery->debug('Rename unnamed pre-beta-3 index to named index (ignore errors)');
1351
ALTER TABLE %sAccessMap
1352
DROP INDEX %saccessListId_2,
1353
ADD INDEX %sAccessMap_83732(%saccessListId);',
1354
$storage->_tablePrefix, $storage->_columnPrefix, $storage->_tablePrefix,
1355
$storage->_columnPrefix);
1356
/* Ignore error, since there's nothing to do for most installations */
1357
$storage->execute($query);
1361
* Combine AccessMap userId/groupId into single userOrGroupId,
1362
* and remove unused GALLERY_PERMISSION_ITEM_ADMIN permission flag.
1363
* Also increase size of GalleryUser::email column.
1365
$ret = $storage->configureStore($module->getId(),
1366
array('GalleryAccessMap:1.0', 'GalleryUser:1.0'));
1368
return $ret->wrap(__FILE__, __LINE__);
1371
/* If coming from 0.9.5 or earlier then GalleryAccessMap already has userOrGroupId */
1372
if (version_compare($currentVersion, '0.9.5', '>')) {
1377
[::userOrGroupId] = [::userId] + [::groupId]
1379
$ret = $storage->execute($query, array());
1381
return $ret->wrap(__FILE__, __LINE__);
1385
$ret = $storage->configureStore($module->getId(), array('GalleryAccessMap:1.1'));
1387
return $ret->wrap(__FILE__, __LINE__);
1390
list ($ret, $flagModifier) =
1391
$storage->getFunctionSql('BITAND', array('[::flags]', '?'));
1393
return $ret->wrap(__FILE__, __LINE__);
1397
[GalleryPermissionSetMap]
1399
[::flags] = ' . $flagModifier . '
1401
$ret = $storage->execute($query, array(3));
1403
return $ret->wrap(__FILE__, __LINE__);
1407
/* Several previous upgrades used 'modules' instead of 'module' with plugin params */
1408
list ($ret, $coreParams) = $module->fetchParameters();
1410
return $ret->wrap(__FILE__, __LINE__);
1412
foreach (array('misc.useShortUrls', 'language.selector') as $key) {
1413
if (isset($coreParams[$key])) {
1414
$ret = $module->removeParameter('misc.useShortUrls');
1416
return $ret->wrap(__FILE__, __LINE__);
1420
foreach (array('cookie.path' => '', 'cookie.domain' => '',
1421
'exec.beNice' => '0', 'repository.updateTime' => '0')
1422
as $key => $value) {
1423
if (!isset($coreParams[$key])) {
1424
$ret = $module->setParameter($key, $value);
1426
return $ret->wrap(__FILE__, __LINE__);
1430
$ret = GalleryCoreApi::removeMapEntry(
1431
'GalleryPluginParameterMap', array('pluginType' => 'modules'));
1433
return $ret->wrap(__FILE__, __LINE__);
1437
/* Add param 'language.useBrowserPref' */
1438
list ($ret, $langCode) = $module->getParameter('default.language');
1440
return $ret->wrap(__FILE__, __LINE__);
1442
$useBrowserPref = '0';
1443
if (empty($langCode)) {
1444
$useBrowserPref = '1';
1445
$ret = $module->setParameter('default.language', 'en_US');
1447
return $ret->wrap(__FILE__, __LINE__);
1450
$ret = $module->setParameter('language.useBrowserPref', $useBrowserPref);
1452
return $ret->wrap(__FILE__, __LINE__);
1456
/* Add config parameter: 'baseUri'*/
1458
/* GalleryCoreApi 7.0 and GalleryModule 3.0 */
1461
* Add fast-download for GalleryDataItems too. Fast-download files are now in
1462
* cache/entity/. Delete the old files in cache/derivative/.
1464
$gallery->guaranteeTimeLimit(60);
1465
$query = 'SELECT [GalleryDerivativeImage::id]
1466
FROM [GalleryDerivativeImage]';
1467
list ($ret, $searchResults) = $gallery->search($query);
1469
return $ret->wrap(__FILE__, __LINE__);
1472
if ($searchResults->resultCount() > 0) {
1473
$derivativeIds = array();
1474
while ($result = $searchResults->nextResult()) {
1475
$derivativeIds[] = $result[0];
1477
$totalDerivatives = count($derivativeIds);
1478
$base = $gallery->getConfig('data.gallery.cache');
1479
$gallery->guaranteeTimeLimit(60);
1481
/* Show a progress bar */
1482
$ret = $statusMonitor->renderStatusMessage(
1483
$module->translate('Deleting old fast-download cache'), '', 0);
1485
return $ret->wrap(__FILE__, __LINE__);
1488
$stepSize = min(100, intval($totalDerivatives / 10));
1489
for ($i = 0; $i < $totalDerivatives; $i++) {
1490
/* Delete the file if it exists */
1491
list ($first, $second) = GalleryDataCache::getCacheTuple($derivativeIds[$i]);
1492
$fastDownloadFilePath = sprintf('%derivative/%s/%s/%d-fast.inc',
1493
$base, $first, $second, $derivativeIds[$i]);
1494
if ($platform->file_exists($fastDownloadFilePath)) {
1495
$platform->unlink($fastDownloadFilePath);
1498
/* Update the progress bar / prevent timouts */
1499
if ($i % $stepSize == 0 || $i == ($totalDerivatives - 1)) {
1500
$gallery->guaranteeTimeLimit(60);
1501
$ret = $statusMonitor->renderStatusMessage(
1502
$module->translate('Deleting old fast-download cache'),
1503
'', ($i+1) / $totalDerivatives);
1505
return $ret->wrap(__FILE__, __LINE__);
1511
/* Added 'not-null' to Entities.inc and Map.inc */
1512
$storageExtras =& $storage->_getExtras();
1513
$storageExtras->_clearEntityAndMapCache();
1515
/* And image/tga mime type */
1516
list ($ret, $mimeType) = GalleryCoreApi::convertExtensionToMime('tga');
1517
if (!$ret && $mimeType == 'application/unknown') {
1518
$ret = GalleryCoreApi::addMimeType('tga', 'image/tga', false);
1520
return $ret->wrap(__FILE__, __LINE__);
1525
/* Add index to GalleryEntity::linkId */
1526
$ret = $storage->configureStore($module->getId(), array('GalleryEntity:1.1'));
1528
return $ret->wrap(__FILE__, __LINE__);
1532
/* Add page level caching and the GalleryCache map */
1533
$acceleration = serialize(array('guest' => array('type' => 'none'),
1534
'user' => array('type' => 'none')));
1535
$ret = GalleryCoreApi::setPluginParameter(
1536
'module', 'core', 'acceleration', $acceleration);
1538
return $ret->wrap(__FILE__, __LINE__);
1542
/* Add configurable captcha security level */
1543
$ret = GalleryCoreApi::setPluginParameter('module', 'core', 'captcha.level', 'MEDIUM');
1545
return $ret->wrap(__FILE__, __LINE__);
1549
/* GallerySession change: Store sessions in the database and no longer on disk */
1550
$sessionsDir = $gallery->getConfig('data.gallery.base') . 'sessions' .
1551
$platform->getDirectorySeparator();
1554
$iterationSize = 5000;
1556
/* Show a progress bar while removing the files */
1557
$ret = $statusMonitor->renderStatusMessage(
1558
$module->translate(array('text' => 'Deleting old session files (iteration %d)',
1559
'arg1' => $iteration)),
1562
return $ret->wrap(__FILE__, __LINE__);
1564
$dir = $platform->opendir($sessionsDir, 'r');
1566
return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__,
1567
"Can't access session dir");
1569
$gallery->guaranteeTimeLimit(60);
1570
while (($filename = $platform->readdir($dir)) !== false) {
1571
if ($filename == '.' || $filename == '..') {
1575
$platform->unlink($sessionsDir . $filename);
1577
/* Update the progress bar / prevent timouts */
1578
if ($count % $stepSize == 0) {
1579
$gallery->guaranteeTimeLimit(60);
1580
$ret = $statusMonitor->renderStatusMessage(
1582
array('text' => 'Deleting old session files (iteration %d)',
1583
'arg1' => $iteration)),
1584
'', $count / $iterationSize);
1586
return $ret->wrap(__FILE__, __LINE__);
1590
if ($count > $iterationSize) {
1595
$platform->closedir($dir);
1596
$platform->rmdir($sessionsDir);
1597
$ret = $statusMonitor->renderStatusMessage(
1598
$module->translate(array('text' => 'Deleting old session files (iteration %d)',
1599
'arg1' => $iteration)),
1602
return $ret->wrap(__FILE__, __LINE__);
1606
/* Rename unnamed pre-beta-3 index to named index */
1607
$gallery->guaranteeTimeLimit(120);
1608
if ($storage->getType() == 'mysql') {
1609
$gallery->debug('Rename unnamed pre-beta-3 index to named index (ignore errors)');
1610
$indexChanges = array();
1611
$indexChanges[] = array('AccessMap', 'permission',
1612
'AccessMap_18058', array('permission'));
1613
$indexChanges[] = array('AccessSubscriberMap', 'accessListId',
1614
'AccessSubscriberMap_83732', array('accessListId'));
1615
$indexChanges[] = array('ChildEntity', 'parentId',
1616
'ChildEntity_52718', array('parentId'));
1617
$indexChanges[] = array('Derivative', 'derivativeSourceId',
1618
'Derivative_85338', array('derivativeSourceId'));
1619
$indexChanges[] = array('Derivative', 'derivativeOrder',
1620
'Derivative_25243', array('derivativeOrder'));
1621
$indexChanges[] = array('Derivative', 'derivativeType',
1622
'Derivative_97216', array('derivativeType'));
1623
$indexChanges[] = array('DerivativePrefsMap', 'itemId',
1624
'DerivativePrefsMap_75985', array('itemId'));
1625
$indexChanges[] = array('Entity', 'creationTimestamp',
1626
'Entity_76255', array('creationTimestamp'));
1627
$indexChanges[] = array('Entity', 'isLinkable',
1628
'Entity_35978', array('isLinkable'));
1629
$indexChanges[] = array('Entity', 'modificationTimestamp',
1630
'Entity_63025', array('modificationTimestamp'));
1631
$indexChanges[] = array('Entity', 'serialNumber',
1632
'Entity_60702', array('serialNumber'));
1633
$indexChanges[] = array('FileSystemEntity ', 'pathComponent',
1634
'FileSystemEntity_3406', array('pathComponent'));
1635
$indexChanges[] = array('Item', 'keywords', 'Item_99070', array('keywords'));
1636
$indexChanges[] = array('Item', 'ownerId', 'Item_21573', array('ownerId'));
1637
$indexChanges[] = array('Item', 'summary', 'Item_54147', array('summary'));
1638
$indexChanges[] = array('Item', 'title', 'Item_90059', array('title'));
1639
$indexChanges[] = array('ItemAttributesMap', 'parentSequence',
1640
'ItemAttributesMap_95270', array('parentSequence'));
1641
$indexChanges[] = array('MaintenanceMap', 'taskId',
1642
'MaintenanceMap_21687', array('taskId'));
1643
$indexChanges[] = array('PluginParameterMap', 'pluginType_2',
1644
'PluginParameterMap_12808',
1645
array('pluginType', 'pluginId', 'itemId'));
1646
$indexChanges[] = array('PluginParameterMap', 'pluginType_3',
1647
'PluginParameterMap_80596', array('pluginType'));
1648
$indexChanges[] = array('TkOperatnMimeTypeMap', 'operationName',
1649
'TkOperatnMimeTypeMap_2014', array('operationName'));
1650
$indexChanges[] = array('TkOperatnMimeTypeMap', 'mimeType',
1651
'TkOperatnMimeTypeMap_79463', array('mimeType'));
1652
$indexChanges[] = array('TkOperatnParameterMap', 'operationName',
1653
'TkOperatnParameterMap_2014', array('operationName'));
1654
$indexChanges[] = array('TkPropertyMimeTypeMap', 'propertyName',
1655
'TkPropertyMimeTypeMap_52881', array('propertyName'));
1656
$indexChanges[] = array('TkPropertyMimeTypeMap', 'mimeType',
1657
'TkPropertyMimeTypeMap_79463', array('mimeType'));
1658
$indexChanges[] = array('UserGroupMap', 'userId',
1659
'UserGroupMap_69068', array('userId'));
1660
$indexChanges[] = array('UserGroupMap', 'groupId',
1661
'UserGroupMap_89328', array('groupId'));
1662
$indexChanges[] = array('Lock', 'lockId',
1663
'Lock_11039', array('lockId'));
1664
foreach ($indexChanges as $change) {
1665
$indexColumns = implode('`, `' . $storage->_columnPrefix, $change[3]);
1666
$indexColumns = $storage->_columnPrefix . $indexColumns;
1670
ADD INDEX `%s%s`(`%s`);',
1671
$storage->_tablePrefix, $change[0], $storage->_columnPrefix, $change[1],
1672
$storage->_tablePrefix, $change[2], $indexColumns);
1673
/* Ignore error, since there's nothing to do for most installations */
1674
$storage->execute($query);
1676
$gallery->debug('Finished renaming unnamed pre-beta-3 indices to named indices');
1679
/* Commit transactions before we execute a query that we expect to fail */
1680
$ret = $storage->checkPoint();
1682
return $ret->wrap(__FILE__, __LINE__);
1686
* Also add a single column index on AccessMap.accessListId since it was forgotten in
1687
* the initial upgrade code. Ignore errors since some installations already have it.
1689
$gallery->debug('Adding an index to the AccessMap table, ignore errors');
1690
$storage->configureStore($module->getId(), array('GalleryAccessMap:1.2'));
1692
/* Postgres will abort the transaction if the index exists, so checkpoint here. */
1693
$ret = $storage->checkpoint();
1695
return $ret->wrap(__FILE__, __LINE__);
1698
$gallery->debug('Finished adding an index to the AccessMap table');
1700
* Make sure the schema update is stored, can't use updateMapEntry because Schema is
1705
SET %smajor=1, %sminor=3
1706
WHERE %sname=\'AccessMap\' AND %smajor=1 AND %sminor=2',
1707
$storage->_tablePrefix, $storage->_columnPrefix,
1708
$storage->_columnPrefix, $storage->_columnPrefix,
1709
$storage->_columnPrefix, $storage->_columnPrefix);
1710
$ret = $storage->execute($query);
1712
return $ret->wrap(__FILE__, __LINE__);
1716
/* Rename GalleryCache to GalleryCacheMap, and make the value column TEXT(LARGE) */
1719
/* Add CoreCaptchaAdminOption, rename level parameter */
1720
$gallery->guaranteeTimeLimit(60);
1721
list ($ret, $level) = $module->getParameter('captcha.level');
1723
return $ret->wrap(__FILE__, __LINE__);
1725
$ret = $module->setParameter('validation.level', $level);
1727
return $ret->wrap(__FILE__, __LINE__);
1729
$ret = $module->removeParameter('captcha.level');
1731
return $ret->wrap(__FILE__, __LINE__);
1736
/* 2.1 Release Candidate 1! */
1738
/* Change character set encoding to utf 8 for MySQL if necessary */
1739
if ($storage->getType() == 'mysql') {
1740
$version = mysql_get_server_info();
1741
/* MySQL < 4.1.0 does not support UTF8 */
1742
if ($version && version_compare($version, '4.1.0', '>=')) {
1743
/* Check if the database uses UTF8 already */
1744
list ($ret, $results) =
1745
$storage->search('SHOW CREATE DATABASE `' . $storage->_database . '`');
1747
return $ret->wrap(__FILE__, __LINE__);
1749
$row = $results->nextResult();
1751
if (!$result || !preg_match('/utf8/i', $result)) {
1752
/* Convert all existing tables to UTF8 */
1753
$ret = $statusMonitor->renderStatusMessage(
1754
$module->translate('Converting MySQL data to UTF8'), null, 0);
1756
return $ret->wrap(__FILE__, __LINE__);
1758
$gallery->guaranteeTimeLimit(120);
1759
$storageExtras =& $storage->_getExtras();
1760
list ($ret, $tableVersions) = $storageExtras->_loadTableVersions();
1762
return $ret->wrap(__FILE__, __LINE__);
1764
$types = array('varchar' => 'varbinary',
1766
'longtext' => 'longblob');
1768
foreach ($tableVersions as $tableName => $unused) {
1770
$tableName = $storage->_tablePrefix . $tableName;
1771
/* First the table itself */
1772
$query = "ALTER TABLE `$tableName` DEFAULT CHARACTER SET utf8";
1773
$ret = $storage->execute($query);
1775
return $ret->wrap(__FILE__, __LINE__);
1778
* Then all character / string columns
1779
* See: http://dev.mysql.com/doc/refman/4.1/en/charset-conversion.html
1780
* and http://drupal.org/node/40515
1781
* 1. Detect current column attributes
1782
* 2. Convert text column to binary column
1783
* 3. Convert them to character/text columns with UTF8 charset
1785
/* 1. Detect current column attributes */
1786
$query = "SHOW FULL COLUMNS FROM `$tableName`";
1787
$originalFetchMode = $storage->_db->SetFetchMode(ADODB_FETCH_ASSOC);
1788
list ($ret, $results) = $storage->search($query);
1790
return $ret->wrap(__FILE__, __LINE__);
1792
$storage->_db->SetFetchMode($originalFetchMode);
1793
$changeToBinary = $changeToUtf8 = array();
1794
while ($column = $results->nextResult()) {
1795
list($type) = explode('(', $column['Type']);
1796
if (!isset($types[$type])) {
1800
'CHANGE `' . $column['Field'] . '` `' . $column['Field'] . '` ';
1801
$binaryType = preg_replace('/'. $type .'/i', $types[$type],
1804
if ($column['Default'] == 'NULL') {
1805
$attributes .= 'DEFAULT NULL ';
1806
} else if (!empty($column['Default'])) {
1807
$attributes .= 'DEFAULT ' . $column['Default'] . ' ';
1809
$attributes .= $column['Null'] == 'YES' ? 'NULL' : 'NOT NULL';
1810
$changeToBinary[] = $change . $binaryType . $attributes;
1812
$change . $column['Type'] . ' CHARACTER SET utf8' . $attributes;
1814
if (count($changeToBinary)) {
1816
"ALTER TABLE `$tableName` " . implode(', ', $changeToBinary);
1817
$ret = $storage->Execute($query);
1819
return $ret->wrap(__FILE__, __LINE__);
1821
$query = "ALTER TABLE `$tableName` " . implode(', ', $changeToUtf8);
1822
$ret = $storage->Execute($query);
1824
return $ret->wrap(__FILE__, __LINE__);
1828
$ret = $statusMonitor->renderStatusMessage(
1829
$module->translate('Converting MySQL data to UTF8'),
1830
null, $i / count($tableVersions));
1832
return $ret->wrap(__FILE__, __LINE__);
1834
$gallery->guaranteeTimeLimit(120);
1835
} /* end for each table */
1836
} /* end if database character set not utf8 */
1837
} /* end if MySql version > 4.1.0 */
1838
} /* end if MySQL */
1840
/* Clear the cache data since we changed the blob encoding */
1841
$gallery->guaranteeTimeLimit(60);
1842
$ret = GalleryCoreApi::removeAllMapEntries('GalleryCacheMap');
1844
return $ret->wrap(__FILE__, __LINE__);
1849
/* Change in page cache key format */
1851
/* Support for transactional locking */
1854
/* Pull dangerous mime types */
1855
$ret = GalleryCoreApi::removeMimeType(
1856
array('mimeType' => array('text/html', 'application/xhtml+xml', 'text/xml')));
1858
return $ret->wrap(__FILE__, __LINE__);
1862
list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'core');
1864
return $ret->wrap(__FILE__, __LINE__);
1866
foreach (array('session.lifetime' => array(25 * 365 * 86400, 21 * 86400),
1867
'session.inactivityTimeout' => array(14 * 86400, 7 * 86400)) as
1868
$key => $oldAndNew) {
1869
if ($params[$key] == $oldAndNew[0]) {
1870
$ret = $module->setParameter($key, $oldAndNew[1]);
1872
return $ret->wrap(__FILE__, __LINE__);
1878
/* 2.1 Release Candidate 2! */
1880
/* Security fix in installer/upgrader - RC-2a */
1884
/* 2.1.1 Bugfix Release */
1214
1886
case 'end of upgrade path':
1216
1888
* Leave this bogus case at the end of the legitimate case statements so that we