~ubuntu-branches/ubuntu/hardy/gallery2/hardy-security

« back to all changes in this revision

Viewing changes to modules/core/CoreModuleExtras.inc

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2006-04-16 16:42:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060416164235-8uy0u4bfjdxpge2o
Tags: 2.1.1-1
* New upstream release (Closes: #362936)
  + Bugfixes for Postgres7 (Closes: #359000, #362152)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * $RCSfile: CoreModuleExtras.inc,v $
4
4
 *
5
5
 * Gallery - a web based photo album viewer and editor
6
 
 * Copyright (C) 2000-2005 Bharat Mediratta
 
6
 * Copyright (C) 2000-2006 Bharat Mediratta
7
7
 *
8
8
 * This program is free software; you can redistribute it and/or modify
9
9
 * it under the terms of the GNU General Public License as published by
20
20
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
21
21
 */
22
22
/**
23
 
 * @version $Revision: 1.113.2.2 $ $Date: 2005/11/24 00:46:16 $
 
23
 * @version $Revision: 1.165.2.2 $ $Date: 2006/04/05 22:19:54 $
24
24
 * @package GalleryCore
25
25
 * @author Bharat Mediratta <bharat@menalto.com>
26
26
 */
44
44
    function upgrade($module, $currentVersion, $statusMonitor) {
45
45
        global $gallery;
46
46
        $storage =& $gallery->getStorage();
 
47
        $platform =& $gallery->getPlatform();
47
48
        $gallery->debug('Entering CoreModuleExtras::upgrade');
48
49
 
49
50
        /*
69
70
                $currentVersion = '0';
70
71
            }
71
72
        }
72
 
 
73
 
        $platform = $gallery->getPlatform();
 
73
        if (substr($currentVersion, 0, 6) == '1.0.0.') {
 
74
            /* Enable upgrade from any Gallery 2.0.x version */
 
75
            $currentVersion = '1.0.0.x';
 
76
        }
74
77
 
75
78
        /**
76
79
         * README: How to update the block below.
85
88
        switch ($currentVersion) {
86
89
        case '0':
87
90
            $gallery->debug('Install core module');
 
91
            /*
 
92
             * Checkpoint (commit configurStore transaction)
 
93
             * Later in the installation code, we create the root album and therefore need
 
94
             * locking. Locks are acquired with a non-transactional db connection. So before we
 
95
             * can query the db with a second connection, the INSERT id into SequenceLock needs to
 
96
             * be committed. Related g2 bug id: 1235284.
 
97
             */
 
98
            $ret = $storage->checkPoint();
 
99
            if ($ret) {
 
100
                return $ret->wrap(__FILE__, __LINE__);
 
101
            }
 
102
 
 
103
            $ret = $statusMonitor->renderStatusMessage(
 
104
                    $module->translate('Installing the core module'), '', 0.15);
 
105
            if ($ret) {
 
106
                return $ret->wrap(__FILE__, __LINE__);
 
107
            }
 
108
            $gallery->guaranteeTimeLimit(180);
 
109
 
88
110
            if (GalleryUtilities::isA($platform, 'WinNtPlatform')) {
89
111
                $flockType = 'database';
90
112
            } else {
100
122
            $gallery->debug(sprintf('Locktype %s selected', $flockType));
101
123
            /* Initial install.  Make sure all our module parameters are set. */
102
124
            $gallery->debug('Set core module parameters');
103
 
            GalleryCoreApi::relativeRequireOnce('modules/core/classes/GalleryTranslator.class');
 
125
            GalleryCoreApi::requireOnce('modules/core/classes/GalleryTranslator.class');
104
126
            foreach (array('permissions.directory' => '0755',
105
127
                           'permissions.file' => '0644',
106
128
                           'exec.expectedStatus' => '0',
 
129
                           'exec.beNice' => '0',
107
130
                           'default.orderBy' => 'orderWeight',
108
131
                           'default.orderDirection' => '1',
109
132
                           'default.theme' => 'matrix',
110
133
                           'default.language' => GalleryTranslator::getLanguageCodeFromRequest(),
 
134
                           'language.useBrowserPref' => '0',
111
135
                           'default.newAlbumsUseDefaults' => 'false',
112
 
                           'language.selector' => 'none',
113
 
                           'session.lifetime' => 25 * 365 * 86400, /* 25 years */
114
 
                           'session.inactivityTimeout' => 14 * 86400, /* two weeks */
 
136
                           'session.lifetime' => 21 * 86400, /* three weeks */
 
137
                           'session.inactivityTimeout' => 7 * 86400, /* one week */
115
138
                           'misc.markup' => 'bbcode',
116
139
                           'lock.system' => $flockType,
117
140
                           'format.date' => '%x',
118
141
                           'format.time' => '%X',
119
 
                           'format.datetime' => '%c'
 
142
                           'format.datetime' => '%c',
 
143
                           'repository.updateTime' => '0',
 
144
                           'acceleration' => serialize(array('guest' => array('type' => 'none'),
 
145
                                                             'user' => array('type' => 'none'))),
 
146
                           'validation.level' => 'MEDIUM',
120
147
                           ) as $key => $value) {
121
148
                if (!isset($param[$key])) {
122
 
                    $ret = $module->setParameter($key, $value);
123
 
                    if ($ret->isError()) {
 
149
                    $ret = $module->setParameter($key, (string)$value);
 
150
                    if ($ret) {
124
151
                        $gallery->debug(sprintf('Error: Failed to set core module parameter %s, ' .
125
152
                                               'this is the error stack trace: %s', $key,
126
153
                                               $ret->getAsText()));
129
156
                }
130
157
            }
131
158
 
 
159
            $ret = $statusMonitor->renderStatusMessage(
 
160
                    $module->translate('Installing the core module'), '', 0.2);
 
161
            if ($ret) {
 
162
                return $ret->wrap(__FILE__, __LINE__);
 
163
            }
 
164
            $gallery->guaranteeTimeLimit(180);
 
165
 
132
166
            /* Activate the Matrix theme */
133
167
            $gallery->debug('Load Matrix theme');
134
168
            list ($ret, $theme) = GalleryCoreApi::loadPlugin('theme', 'matrix');
135
 
            if ($ret->isError()) {
 
169
            if ($ret) {
136
170
                $gallery->debug(sprintf('Error: Failed to load matrix theme, this is the error ' .
137
171
                                'stack trace; %s', $ret->getAsText()));
138
172
                return $ret->wrap(__FILE__, __LINE__);
139
173
            }
140
174
 
 
175
            $ret = $statusMonitor->renderStatusMessage(
 
176
                    $module->translate('Installing the core module'), '', 0.25);
 
177
            if ($ret) {
 
178
                return $ret->wrap(__FILE__, __LINE__);
 
179
            }
 
180
            $gallery->guaranteeTimeLimit(180);
 
181
 
141
182
            $gallery->debug('InstallOrUpgrade Matrix theme');
142
183
            $ret = $theme->installOrUpgrade();
143
 
            if ($ret->isError()) {
 
184
            if ($ret) {
144
185
                $gallery->debug(sprintf('Error: Failed to installOrUpgrade matrix theme, this is ' .
145
186
                                'the error stack trace; %s', $ret->getAsText()));
146
187
                return $ret->wrap(__FILE__, __LINE__);
147
188
            }
148
189
 
 
190
            $ret = $statusMonitor->renderStatusMessage(
 
191
                    $module->translate('Installing the core module'), '', 0.3);
 
192
            if ($ret) {
 
193
                return $ret->wrap(__FILE__, __LINE__);
 
194
            }
 
195
            $gallery->guaranteeTimeLimit(180);
 
196
 
149
197
            $gallery->debug('Activate Matrix theme');
150
 
            list ($ret, $ignored) = $theme->activate();
151
 
            if ($ret->isError()) {
 
198
            list ($ret, $ignored) = $theme->activate(false);
 
199
            if ($ret) {
152
200
                $gallery->debug(sprintf('Error: Failed to activate matrix theme, this is ' .
153
201
                                'the error stack trace; %s', $ret->getAsText()));
154
202
                return $ret->wrap(__FILE__, __LINE__);
155
203
            }
156
204
 
 
205
            $ret = $statusMonitor->renderStatusMessage(
 
206
                    $module->translate('Installing the core module'), '', 0.4);
 
207
            if ($ret) {
 
208
                return $ret->wrap(__FILE__, __LINE__);
 
209
            }
 
210
            $gallery->guaranteeTimeLimit(180);
 
211
 
157
212
            /*
158
213
             * Register our permissions.  Since we're storing internationalized
159
214
             * strings in the database, we have to give our internationalized
173
228
                                   GALLERY_PERMISSION_COMPOSITE,
174
229
                                   array('core.view', 'core.viewResizes', 'core.viewSource'));
175
230
            $permissions[] = array('addAlbumItem', $gallery->i18n('[core] Add sub-album'),
176
 
                                   GALLERY_PERMISSION_ITEM_ADMIN, array());
 
231
                                   0, array());
177
232
            $permissions[] = array('addDataItem', $gallery->i18n('[core] Add sub-item'),
178
 
                                   GALLERY_PERMISSION_ITEM_ADMIN, array());
179
 
            $permissions[] = array('edit', $gallery->i18n('[core] Edit item'),
180
 
                                   GALLERY_PERMISSION_ITEM_ADMIN, array());
 
233
                                   0, array());
 
234
            $permissions[] = array('edit', $gallery->i18n('[core] Edit item'), 0, array());
181
235
            $permissions[] = array('changePermissions',
182
 
                                   $gallery->i18n('[core] Change item permissions'),
183
 
                                   GALLERY_PERMISSION_ITEM_ADMIN, array());
184
 
            $permissions[] = array('delete', $gallery->i18n('[core] Delete item'),
185
 
                                   GALLERY_PERMISSION_ITEM_ADMIN, array());
 
236
                                   $gallery->i18n('[core] Change item permissions'), 0, array());
 
237
            $permissions[] = array('delete', $gallery->i18n('[core] Delete item'), 0, array());
186
238
            foreach ($permissions as $p) {
187
239
                $ret = GalleryCoreApi::registerPermission(
188
240
                    $module->getId(), 'core.' . $p[0], $p[1], $p[2], $p[3]);
189
 
                if ($ret->isError()) {
 
241
                if ($ret) {
190
242
                    $gallery->debug(sprintf('Error: Failed to register a permission, ' .
191
 
                                               'this is the error stack trace: %s',
192
 
                                           $ret->getAsText()));
 
243
                                            'this is the error stack trace: %s',
 
244
                                            $ret->getAsText()));
193
245
                    return $ret->wrap(__FILE__, __LINE__);
194
246
                }
195
247
            }
196
248
 
 
249
            $ret = $statusMonitor->renderStatusMessage(
 
250
                    $module->translate('Installing the core module'), '', 0.5);
 
251
            if ($ret) {
 
252
                return $ret->wrap(__FILE__, __LINE__);
 
253
            }
 
254
            $gallery->guaranteeTimeLimit(180);
 
255
 
197
256
            foreach (array('_createAccessListCompacterLock',
198
257
                           '_createAllUsersGroup',
199
258
                           '_createSiteAdminsGroup',
204
263
 
205
264
                $gallery->debug(sprintf('Call user func %s', $func));
206
265
                $ret = call_user_func(array('CoreModuleExtras', $func), $module);
207
 
                if ($ret->isError()) {
 
266
                if ($ret) {
208
267
                    $gallery->debug(sprintf('Error: %s returned an error, ' .
209
268
                                           'this is the error stack trace: %s', $func,
210
269
                                           $ret->getAsText()));
212
271
                }
213
272
            }
214
273
 
 
274
            $ret = $statusMonitor->renderStatusMessage(
 
275
                    $module->translate('Installing the core module'), '', 0.6);
 
276
            if ($ret) {
 
277
                return $ret->wrap(__FILE__, __LINE__);
 
278
            }
 
279
            $gallery->guaranteeTimeLimit(180);
 
280
 
215
281
            $gallery->debug('Initialize MIME types');
216
 
            GalleryCoreApi::relativeRequireOnce(
 
282
            GalleryCoreApi::requireOnce(
217
283
                'modules/core/classes/helpers/GalleryMimeTypeHelper_advanced.class');
218
284
            $ret = GalleryMimeTypeHelper_advanced::initializeMimeTypes();
219
 
            if ($ret->isError()) {
 
285
            if ($ret) {
220
286
                $gallery->debug(sprintf('Error: Failed to initialize MIME types, this is ' .
221
287
                                        'the error stack trace: %s', $ret->getAsText()));
222
288
                return $ret->wrap(__FILE__, __LINE__);
223
289
            }
224
290
            $gallery->debug('CoreModulesExtra::upgrade: successfully installed core');
 
291
 
 
292
            $ret = $statusMonitor->renderStatusMessage(
 
293
                    $module->translate('Installing the core module'), '', 0.7);
 
294
            if ($ret) {
 
295
                return $ret->wrap(__FILE__, __LINE__);
 
296
            }
 
297
            $gallery->guaranteeTimeLimit(180);
225
298
            break;
226
299
 
227
300
        case '0.8':
245
318
               [GalleryPluginParameterMap::itemId] = 0
246
319
            ';
247
320
            $ret = $storage->execute($query, array('_version', 'version'));
248
 
            if ($ret->isError()) {
 
321
            if ($ret) {
249
322
                return $ret->wrap(__FILE__, __LINE__);
250
323
            }
251
324
 
252
325
            $ret = $storage->execute($query, array('_callbacks', 'callbacks'));
253
 
            if ($ret->isError()) {
 
326
            if ($ret) {
254
327
                return $ret->wrap(__FILE__, __LINE__);
255
328
            }
256
329
 
257
330
            /* Added a new parameter */
258
331
            $ret = $module->setParameter('misc.login', 'both');
259
 
            if ($ret->isError()) {
 
332
            if ($ret) {
260
333
                return $ret->wrap(__FILE__, __LINE__);
261
334
            }
262
335
 
263
336
        case '0.8.3':
264
337
        case '0.8.4':
265
338
        case '0.8.5':
266
 
            /*
267
 
             * Copy the information from viewedSinceTimestamp to originationTimestamp
268
 
             * as both default to time()
269
 
             */
 
339
            /* Added GalleryItem::originationTimestamp */
 
340
            $ret = $storage->configureStore($module->getId(), array('GalleryItem:1.0'));
 
341
            if ($ret) {
 
342
                return $ret->wrap(__FILE__, __LINE__);
 
343
            }
 
344
 
 
345
            /* Copy viewedSinceTimestamp to originationTimestamp as both default to time() */
270
346
            $query = '
271
347
            UPDATE
272
348
              [GalleryItem]
274
350
              [::originationTimestamp] = [::viewedSinceTimestamp]
275
351
            ';
276
352
            $ret = $storage->execute($query, array());
277
 
            if ($ret->isError()) {
 
353
            if ($ret) {
278
354
                return $ret->wrap(__FILE__, __LINE__);
279
355
            }
280
356
 
281
357
        case '0.8.6':
282
358
        case '0.8.7':
283
359
            $ret = $module->setParameter('default.newAlbumsUseDefaults', 'false');
284
 
            if ($ret->isError()) {
 
360
            if ($ret) {
285
361
                return $ret->wrap(__FILE__, __LINE__);
286
362
            }
287
363
 
292
368
             * wait until upgrade() completes to register during reactivate()..
293
369
             */
294
370
            $ret = CoreModuleExtras::performFactoryRegistrations($module);
295
 
            if ($ret->isError()) {
 
371
            if ($ret) {
296
372
                return $ret->wrap(__FILE__, __LINE__);
297
373
            }
298
374
 
304
380
             */
305
381
            $query = 'UPDATE [GalleryFactoryMap] SET [::orderWeight] = 5';
306
382
            $ret = $storage->execute($query, array());
307
 
            if ($ret->isError()) {
 
383
            if ($ret) {
308
384
                return $ret->wrap(__FILE__, __LINE__);
309
385
            }
310
386
 
312
388
        case '0.8.11':
313
389
        case '0.8.12':
314
390
            $ret = $module->setParameter('lock.system', 'flock');
315
 
            if ($ret->isError()) {
 
391
            if ($ret) {
316
392
                return $ret->wrap(__FILE__, __LINE__);
317
393
            }
318
394
 
320
396
            /* We used to add layout versioning here.  Now that's been moved to the 0.9.29 block */
321
397
 
322
398
        case '0.8.14':
323
 
            /* Added Entity::onLoadHandlers; default all values to null, so nothing to do */
 
399
            /* Added Entity::onLoadHandlers; default all values to null */
 
400
            $ret = $storage->configureStore($module->getId(), array('GalleryEntity:1.0'));
 
401
            if ($ret) {
 
402
                return $ret->wrap(__FILE__, __LINE__);
 
403
            }
324
404
 
325
405
        case '0.8.15':
326
 
            $gallery->guaranteeTimeLimit(30);
327
 
            /* Removed GalleryItemPropertiesMap.. drop the table */
328
 
            /* R_GalleryItemPropertiesMap_1.0 now takes care of this:
329
 
            * $query = 'DROP TABLE [GalleryItemPropertiesMap]';
330
 
            * $ret = $storage->execute($query);
331
 
            * if ($ret->isError()) {
332
 
            *     return $ret->wrap(__FILE__, __LINE__);
333
 
            * }
334
 
            * $query = "DELETE FROM [Schema] WHERE [Schema::name] = 'ItemPropertiesMap'";
335
 
            * $ret = $storage->execute($query);
336
 
            * if ($ret->isError()) {
337
 
            *     return $ret->wrap(__FILE__, __LINE__);
338
 
            * }
339
 
            */
 
406
            /* Removed GalleryItemPropertiesMap */
340
407
 
341
408
        case '0.8.16':
342
409
            /* Schema updates: GalleryPluginMap, GalleryPluginParameterMap, GalleryGroup */
 
410
            $ret = $storage->configureStore($module->getId(),
 
411
                array('GalleryPluginMap:1.0', 'GalleryPluginParameterMap:1.0', 'GalleryGroup:1.0'));
 
412
            if ($ret) {
 
413
                return $ret->wrap(__FILE__, __LINE__);
 
414
            }
343
415
 
344
416
        case '0.8.17':
345
417
            /* Beta 1! */
346
418
 
347
419
        case '0.9.0':
348
 
            $ret = GalleryCoreApi::removePluginParameter('modules', 'core', 'misc.useShortUrls');
349
 
            if ($ret->isError()) {
 
420
            $ret = $module->removeParameter('misc.useShortUrls');
 
421
            if ($ret) {
350
422
                return $ret->wrap(__FILE__, __LINE__);
351
423
            }
352
424
 
361
433
 
362
434
        case '0.9.4':
363
435
            $gallery->guaranteeTimeLimit(30);
364
 
            GalleryCoreApi::relativeRequireOnce(
 
436
            GalleryCoreApi::requireOnce(
365
437
                'modules/core/classes/helpers/GalleryMimeTypeHelper_advanced.class');
366
438
            $ret = GalleryMimeTypeHelper_advanced::initializeMimeTypes();
367
 
            if ($ret->isError()) {
 
439
            if ($ret) {
368
440
                return $ret->wrap(__FILE__, __LINE__);
369
441
            }
370
442
 
371
443
        case '0.9.5':
372
444
            $gallery->guaranteeTimeLimit(30);
373
445
            $ret = CoreModuleExtras::_createAccessListCompacterLock($module);
374
 
            if ($ret->isError()) {
 
446
            if ($ret) {
375
447
                return $ret->wrap(__FILE__, __LINE__);
376
448
            }
377
449
 
407
479
              [GalleryPermissionMap::itemId] = ?
408
480
            ';
409
481
 
 
482
            /* Updated this query for core 1.0.11 to write to userOrGroupId column */
410
483
            $createAclQuery = '
411
484
            INSERT INTO
412
 
              [GalleryAccessMap] ([::accessListId], [::userId], [::groupId], [::permission])
 
485
              [GalleryAccessMap] ([::accessListId], [::userOrGroupId], [::permission])
413
486
            SELECT
414
 
              ?, [GalleryPermissionMap::userId],
415
 
              [GalleryPermissionMap::groupId], [GalleryPermissionMap::permission]
 
487
              ?,
 
488
              [GalleryPermissionMap::userId] + [GalleryPermissionMap::groupId],
 
489
              [GalleryPermissionMap::permission]
416
490
            FROM
417
491
              [GalleryPermissionMap]
418
492
            WHERE
472
546
            /* Determine how many items we are going to process for our status message */
473
547
            list ($ret, $results) =
474
548
                $gallery->search($totalRowsQuery, array(), array('limit' => array('count' => 1)));
475
 
            if ($ret->isError()) {
 
549
            if ($ret) {
476
550
                return $ret->wrap(__FILE__, __LINE__);
477
551
            }
478
552
            if ($results->resultCount() == 0) {
487
561
                    $module->translate('Upgrading permissions'),
488
562
                    null,
489
563
                    $itemsProcessed / $totalPermissionItems);
490
 
                if ($ret->isError()) {
 
564
                if ($ret) {
491
565
                    return $ret->wrap(__FILE__, __LINE__);
492
566
                }
493
567
            }
497
571
 
498
572
                /* Find the next item in the permissions table */
499
573
                list ($ret, $results) = $storage->search($findItemIdQuery);
500
 
                if ($ret->isError()) {
 
574
                if ($ret) {
501
575
                    return $ret->wrap(__FILE__, __LINE__);
502
576
                }
503
577
                if ($results->resultCount() == 0) {
508
582
 
509
583
                /* Create a new ACL */
510
584
                list ($ret, $newAclId) = $storage->getUniqueId();
511
 
                if ($ret->isError()) {
 
585
                if ($ret) {
512
586
                    return $ret->wrap(__FILE__, __LINE__);
513
587
                }
514
588
 
515
589
                $ret = $storage->execute($createAclQuery, array($newAclId, $targetItemId));
516
 
                if ($ret->isError()) {
 
590
                if ($ret) {
517
591
                    return $ret->wrap(__FILE__, __LINE__);
518
592
                }
519
593
 
526
600
                 */
527
601
                list ($ret, $results) = $gallery->search(
528
602
                    $findPossibleDupesQuery, array($targetItemId, $permissionRowCount));
529
 
                if ($ret->isError()) {
 
603
                if ($ret) {
530
604
                    return $ret->wrap(__FILE__, __LINE__);
531
605
                }
532
606
                $possibleDupeIds = array();
570
644
                    /* Set all the dupe items in this chunk to use the new ACL */
571
645
                    $query = sprintf($assignAclQuery, $markers);
572
646
                    $ret = $storage->execute($query, array_merge(array($newAclId), $dupeIds));
573
 
                    if ($ret->isError()) {
 
647
                    if ($ret) {
574
648
                        return $ret->wrap(__FILE__, __LINE__);
575
649
                    }
576
650
 
577
651
                    /* Remove all the permission rows for the migrated items */
578
652
                    $query = sprintf($deleteOldPermsQuery, $markers);
579
653
                    $ret = $storage->execute($query, $dupeIds);
580
 
                    if ($ret->isError()) {
 
654
                    if ($ret) {
581
655
                        return $ret->wrap(__FILE__, __LINE__);
582
656
                    }
583
657
 
590
664
                            'arg2' => $totalPermissionItems - $itemsProcessed)),
591
665
                        '',
592
666
                        $itemsProcessed / $totalPermissionItems);
593
 
                    if ($ret->isError()) {
 
667
                    if ($ret) {
594
668
                        return $ret->wrap(__FILE__, __LINE__);
595
669
                    }
596
670
                }
601
675
                    $module->translate('Deleting old permission tables'),
602
676
                    '',
603
677
                    $itemsProcessed / $totalPermissionItems);
604
 
                if ($ret->isError()) {
 
678
                if ($ret) {
605
679
                    return $ret->wrap(__FILE__, __LINE__);
606
680
                }
607
681
            }
608
682
 
609
 
            /* Removed GalleryPermissionsMap.  Drop the table */
610
 
            /* R_GalleryPermissionMap_1.0 now takes care of this:
611
 
            * $query = 'DROP TABLE [GalleryPermissionMap]';
612
 
            * $ret = $storage->execute($query);
613
 
            * if ($ret->isError()) {
614
 
            *     return $ret->wrap(__FILE__, __LINE__);
615
 
            * }
616
 
            * $query = "DELETE FROM [Schema] WHERE [Schema::name] = 'PermissionMap'";
617
 
            * $ret = $storage->execute($query);
618
 
            * if ($ret->isError()) {
619
 
            *     return $ret->wrap(__FILE__, __LINE__);
620
 
            * }
621
 
            */
 
683
            /* Removed GalleryPermissionMap */
622
684
 
623
685
        case '0.9.6':
624
686
            /* Added GalleryMaintenance table */
629
691
             * is transient so just delete it. Added FlushTemplatesTask, FlushDatabaseCacheTask
630
692
             */
631
693
            $gallery->guaranteeTimeLimit(30);
632
 
            GalleryCoreApi::relativeRequireOnce('modules/core/classes/GalleryMaintenanceMap.class');
633
 
            $ret = GalleryMaintenanceMap::removeAllMapEntries();
634
 
            if ($ret->isError()) {
 
694
            $ret = GalleryCoreApi::removeAllMapEntries('GalleryMaintenanceMap');
 
695
            if ($ret) {
635
696
                return $ret->wrap(__FILE__, __LINE__);
636
697
            }
637
698
 
639
700
            /*
640
701
             * Create 'plugins' and 'plugins_data' directories in g2data.  Remove trailing slash
641
702
             * for config paths using substr so file_exists can detect either file or dir.
 
703
             * Update: in core 1.0.6 the data.gallery.plugins dir moved under gallery2 basedir,
 
704
             * not in g2data anymore; we may not have permission to create a dir here.
 
705
             * So code below is now updated to not require those mkdirs to succeed.
642
706
             */
643
707
            $gallery->guaranteeTimeLimit(30);
644
 
            foreach (array(substr($gallery->getConfig('data.gallery.plugins'), 0, -1),
645
 
                           $gallery->getConfig('data.gallery.plugins') . 'modules',
646
 
                           $gallery->getConfig('data.gallery.plugins') . 'layouts',
647
 
                           substr($gallery->getConfig('data.gallery.plugins_data'), 0, -1),
648
 
                           $gallery->getConfig('data.gallery.plugins_data') . 'modules',
649
 
                           $gallery->getConfig('data.gallery.plugins_data') . 'layouts') as $dir) {
 
708
            foreach (array(substr($gallery->getConfig('data.gallery.plugins'), 0, -1) => false,
 
709
                           $gallery->getConfig('data.gallery.plugins') . 'modules' => false,
 
710
                           $gallery->getConfig('data.gallery.plugins') . 'layouts' => false,
 
711
                           substr($gallery->getConfig('data.gallery.plugins_data'), 0, -1) => true,
 
712
                           $gallery->getConfig('data.gallery.plugins_data') . 'modules' => true,
 
713
                           $gallery->getConfig('data.gallery.plugins_data') . 'layouts' => true)
 
714
                    as $dir => $isRequired) {
650
715
                if ($platform->file_exists($dir)) {
651
716
                    if ($platform->is_dir($dir)) {
652
717
                        /* No need to do anything.  Except maybe we could check permissions here. */
654
719
                        /* There's a file there.  There shouldn't be.  Move it out of the way */
655
720
                        if (!@$platform->rename($newDir, "$newDir.old") ||
656
721
                                !@$platform->mkdir($dir)) {
657
 
                            return GalleryStatus::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__,
 
722
                            return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__,
658
723
                                "$dir already exists; unable to replace it");
659
724
                        }
660
725
                    }
661
726
                } else {
662
 
                    if (!@$platform->mkdir($dir)) {
663
 
                        return GalleryStatus::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__,
 
727
                    if (!@$platform->mkdir($dir) && $isRequired) {
 
728
                        return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__,
664
729
                                                    "Unable to create $dir");
665
730
                    }
666
731
                }
690
755
             */
691
756
            list ($ret, $group) =
692
757
                GalleryCoreApi::fetchGroupByGroupName($module->translate('Registered Users'));
693
 
            if ($ret->isError()) {
 
758
            if ($ret) {
694
759
                if ($ret->getErrorCode() & ERROR_MISSING_OBJECT) {
695
760
                    /* Ok, we can change the group name */
696
761
 
697
762
                    list ($ret, $allUserGroupId) = $module->getParameter('id.allUserGroup');
698
 
                    if ($ret->isError()) {
 
763
                    if ($ret) {
699
764
                        return $ret->wrap(__FILE__, __LINE__);
700
765
                    }
701
766
                    list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($allUserGroupId);
702
 
                    if ($ret->isError()) {
 
767
                    if ($ret) {
703
768
                        return $ret->wrap(__FILE__, __LINE__);
704
769
                    }
705
770
                    list ($ret, $group) = GalleryCoreApi::loadEntitiesById($allUserGroupId);
706
 
                    if ($ret->isError()) {
 
771
                    if ($ret) {
707
772
                        return $ret->wrap(__FILE__, __LINE__);
708
773
                    }
709
774
                    $allUserGroupName = $group->getGroupName();
713
778
                    if (!strcmp($allUserGroupName, $originalGroupName)) {
714
779
                        $group->setGroupName($module->translate('Registered Users'));
715
780
                        $ret = $group->save();
716
 
                        if ($ret->isError()) {
 
781
                        if ($ret) {
717
782
                            return $ret->wrap(__FILE__, __LINE__);
718
783
                        }
719
784
 
720
785
                        $ret = GalleryCoreApi::releaseLocks($lockId);
721
 
                        if ($ret->isError()) {
 
786
                        if ($ret) {
722
787
                            return $ret->wrap(__FILE__, __LINE__);
723
788
                        }
724
789
                    }
733
798
        case '0.9.17':
734
799
            /* Split uploadLocalServer.dirs list into one parameter per entry */
735
800
            list ($ret, $dirList) = $module->getParameter('uploadLocalServer.dirs');
736
 
            if ($ret->isError()) {
 
801
            if ($ret) {
737
802
                return $ret->wrap(__FILE__, __LINE__);
738
803
            }
739
804
            if (!empty($dirList)) {
740
805
                $dirList = explode(',', $dirList);
741
806
                for ($i = 1; $i <= count($dirList); $i++) {
742
807
                    $ret = $module->setParameter('uploadLocalServer.dir.' . $i, $dirList[$i - 1]);
743
 
                    if ($ret->isError()) {
 
808
                    if ($ret) {
744
809
                        return $ret->wrap(__FILE__, __LINE__);
745
810
                    }
746
811
                }
747
812
            }
748
813
            $ret = $module->removeParameter('uploadLocalServer.dirs');
749
 
            if ($ret->isError()) {
 
814
            if ($ret) {
750
815
                return $ret->wrap(__FILE__, __LINE__);
751
816
            }
752
817
 
753
818
        case '0.9.18':
754
819
            /* Add image/x-photo-cd mime type */
755
820
            list ($ret, $mimeType) = GalleryCoreApi::convertExtensionToMime('pcd');
756
 
            if ($ret->isSuccess() && $mimeType == 'application/unknown') {
 
821
            if (!$ret && $mimeType == 'application/unknown') {
757
822
                $ret = GalleryCoreApi::addMimeType('pcd', 'image/x-photo-cd', false);
758
 
                if ($ret->isError()) {
 
823
                if ($ret) {
759
824
                    return $ret->wrap(__FILE__, __LINE__);
760
825
                }
761
826
            }
772
837
        case '0.9.23':
773
838
            /* Session cookie change, revert the last change and try something new */
774
839
            foreach (array('cookie.path', 'cookie.domain') as $parameterName) {
775
 
                $ret = GalleryCoreApi::setPluginParameter('modules', 'core', $parameterName, '');
776
 
                if ($ret->isError()) {
 
840
                $ret = $module->setParameter($parameterName, '');
 
841
                if ($ret) {
777
842
                    return $ret->wrap(__FILE__, __LINE__);
778
843
                }
779
844
            }
781
846
        case '0.9.24':
782
847
            /* Add image/jpeg-cmyk mime type */
783
848
            list ($ret, $mimeType) = GalleryCoreApi::convertExtensionToMime('jpgcmyk');
784
 
            if ($ret->isSuccess() && $mimeType == 'application/unknown') {
 
849
            if (!$ret && $mimeType == 'application/unknown') {
785
850
                $ret = GalleryCoreApi::addMimeType('jpgcmyk', 'image/jpeg-cmyk', false);
786
 
                if ($ret->isError()) {
 
851
                if ($ret) {
787
852
                    return $ret->wrap(__FILE__, __LINE__);
788
853
                }
789
854
            }
790
855
        case '0.9.25':
791
856
            /* And image/tiff-cmyk mime type */
792
857
            list ($ret, $mimeType) = GalleryCoreApi::convertExtensionToMime('tifcmyk');
793
 
            if ($ret->isSuccess() && $mimeType == 'application/unknown') {
 
858
            if (!$ret && $mimeType == 'application/unknown') {
794
859
                $ret = GalleryCoreApi::addMimeType('tifcmyk', 'image/tiff-cmyk', false);
795
 
                if ($ret->isError()) {
 
860
                if ($ret) {
796
861
                    return $ret->wrap(__FILE__, __LINE__);
797
862
                }
798
863
            }
799
864
        case '0.9.26':
800
 
            /* Added GalleryDerivative::isBroken; default all values to null, so nothing to do */
 
865
            /* Added GalleryDerivative::isBroken; default all values to null */
 
866
            $ret = $storage->configureStore($module->getId(), array('GalleryDerivative:1.0'));
 
867
            if ($ret) {
 
868
                return $ret->wrap(__FILE__, __LINE__);
 
869
            }
 
870
 
801
871
        case '0.9.27':
802
872
            /* Mark old broken derivatives as such with our new isBroken flag */
803
873
            /*
813
883
            /*
814
884
             * 1. Get a list of all derivatives that are not already marked as isBroken
815
885
             *    (We can't count on derivativeSize being correct, so check all derivatives)
 
886
             * Update: upgrade from pre-beta-1 will fail to load RandomHighlightDerivativeImage
 
887
             *         so restrict this query to only GalleryDerivativeImage
816
888
             */
817
889
            $gallery->guaranteeTimeLimit(60);
818
 
            list ($ret, $results) =
819
890
            $query = 'SELECT [GalleryDerivative::id]
820
 
                      FROM [GalleryDerivative]
821
 
                      WHERE [GalleryDerivative::isBroken] IS NULL';
 
891
                      FROM [GalleryDerivative], [GalleryEntity]
 
892
                      WHERE [GalleryDerivative::isBroken] IS NULL
 
893
                      AND [GalleryDerivative::id] = [GalleryEntity::id]
 
894
                      AND [GalleryEntity::entityType] = \'GalleryDerviativeImage\'';
822
895
            list ($ret, $searchResults) = $gallery->search($query);
823
 
            if ($ret->isError()) {
 
896
            if ($ret) {
824
897
                return $ret->wrap(__FILE__, __LINE__);
825
898
            }
826
899
 
844
917
                /* Show a progress bar */
845
918
                $ret = $statusMonitor->renderStatusMessage(
846
919
                    $module->translate('Detecting broken derivatives'), '', 0);
847
 
                if ($ret->isError()) {
 
920
                if ($ret) {
848
921
                    return $ret->wrap(__FILE__, __LINE__);
849
922
                }
850
923
 
875
948
                                      'arg1' => $itemsProcessed,
876
949
                                      'arg2' => sizeof($derivativeIds))),
877
950
                            '',  $itemsProcessed / $totalDerivatives);
878
 
                        if ($ret->isError()) {
 
951
                        if ($ret) {
879
952
                            return $ret->wrap(__FILE__, __LINE__);
880
953
                        }
881
954
 
882
955
                        $currentDerivativeIds = array_splice($derivativeIds, 0, $loadBatchSize);
883
956
                        list ($ret, $derivatives) =
884
957
                            GalleryCoreApi::loadEntitiesById($currentDerivativeIds);
885
 
                        if ($ret->isError()) {
 
958
                        if ($ret) {
886
959
                            return $ret->wrap(__FILE__, __LINE__);
887
960
                        }
888
961
                    }
906
979
                                          'arg1' => $itemsProcessed,
907
980
                                          'arg2' => $totalDerivatives - $itemsProcessed)),
908
981
                                '', $itemsProcessed / $totalDerivatives);
909
 
                            if ($ret->isError()) {
 
982
                            if ($ret) {
910
983
                                return $ret->wrap(__FILE__, __LINE__);
911
984
                            }
912
985
                            $gallery->guaranteeTimeLimit(30);
917
990
                         *    (= don't have a cache file yet = would be rebuilt anyway)
918
991
                         */
919
992
                        list ($ret, $current) = $derivative->isCacheCurrent();
920
 
                        if ($ret->isError()) {
 
993
                        if ($ret) {
921
994
                            return $ret->wrap(__FILE__, __LINE__);
922
995
                        }
923
996
                        if (!$current) {
929
1002
                         *    broken image placeholder
930
1003
                         */
931
1004
                        list($ret, $path) = $derivative->fetchPath();
932
 
                        if ($ret->isError()) {
 
1005
                        if ($ret) {
933
1006
                            return $ret->wrap(__FILE__, __LINE__);
934
1007
                        }
935
1008
                        if (($size = $platform->filesize($path)) === false) {
936
 
                            return GalleryStatus::error(ERROR_PLATFORM_FAILURE, __FILE__,
 
1009
                            return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__,
937
1010
                                                        __LINE__);
938
1011
                        }
939
1012
                        if ($size != $referenceSize) {
942
1015
 
943
1016
                        /* 5. Binary compare the derivative file with the placeholder file */
944
1017
                        if (($data = $platform->file($path)) === false) {
945
 
                            return GalleryStatus::error(ERROR_PLATFORM_FAILURE, __FILE__,
 
1018
                            return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__,
946
1019
                                                        __LINE__);
947
1020
                        }
948
1021
                        $data = implode('', $data);
966
1039
                                      'arg1' => $itemsProcessed,
967
1040
                                      'arg2' => $totalDerivatives - $itemsProcessed)),
968
1041
                            '', $itemsProcessed / $totalDerivatives);
969
 
                        if ($ret->isError()) {
 
1042
                        if ($ret) {
970
1043
                            return $ret->wrap(__FILE__, __LINE__);
971
1044
                        }
972
1045
 
973
1046
                        list ($ret, $lockId) =
974
1047
                            GalleryCoreApi::acquireWriteLock(array_keys($brokenDerivatives));
975
 
                        if ($ret->isError()) {
 
1048
                        if ($ret) {
976
1049
                            return $ret->wrap(__FILE__, __LINE__);
977
1050
                        }
978
1051
 
990
1063
                                              'arg3' => $itemsProcessed,
991
1064
                                              'arg4' => $totalDerivatives - $itemsProcessed)),
992
1065
                                    '', $itemsProcessed / $totalDerivatives);
993
 
                                if ($ret->isError()) {
 
1066
                                if ($ret) {
994
1067
                                    GalleryCoreApi::releaseLocks($lockId);
995
1068
                                    return $ret->wrap(__FILE__, __LINE__);
996
1069
                                }
998
1071
                            }
999
1072
 
1000
1073
                            $brokenDerivative->setIsBroken(true);
1001
 
                            $ret = $brokenDerivative->save(false);
1002
 
                            if ($ret->isError()) {
 
1074
                            $ret = $brokenDerivative->save(true, false);
 
1075
                            if ($ret) {
1003
1076
                                GalleryCoreApi::releaseLocks($lockId);
1004
1077
                                return $ret->wrap(__FILE__, __LINE__);
1005
1078
                            }
1007
1080
                        $brokenDerivatives = array();
1008
1081
 
1009
1082
                        $ret = GalleryCoreApi::releaseLocks($lockId);
1010
 
                        if ($ret->isError()) {
 
1083
                        if ($ret) {
1011
1084
                            return $ret->wrap(__FILE__, __LINE__);
1012
1085
                        }
1013
1086
                    }
1024
1097
 
1025
1098
        case '0.9.29':
1026
1099
            /* Ginormous layout and theme consolidation refactor */
 
1100
            $ret = $storage->configureStore($module->getId(),
 
1101
                                            array('GalleryPluginParameterMap:1.1'));
 
1102
            if ($ret) {
 
1103
                return $ret->wrap(__FILE__, __LINE__);
 
1104
            }
1027
1105
 
1028
1106
            $query = '
1029
1107
            UPDATE
1034
1112
              [GalleryPluginParameterMap::pluginType] = \'layout\'
1035
1113
            ';
1036
1114
            $ret = $storage->execute($query);
1037
 
            if ($ret->isError()) {
 
1115
            if ($ret) {
1038
1116
                return $ret->wrap(__FILE__, __LINE__);
1039
1117
            }
1040
1118
 
1046
1124
              [::theme] = \'matrix\'
1047
1125
            ';
1048
1126
            $ret = $storage->execute($query);
1049
 
            if ($ret->isError()) {
 
1127
            if ($ret) {
1050
1128
                return $ret->wrap(__FILE__, __LINE__);
1051
1129
            }
1052
1130
 
1059
1137
              [GalleryPluginMap::pluginType] = \'layout\'
1060
1138
            ';
1061
1139
            $ret = $storage->execute($query);
1062
 
            if ($ret->isError()) {
 
1140
            if ($ret) {
1063
1141
                return $ret->wrap(__FILE__, __LINE__);
1064
1142
            }
1065
1143
 
1073
1151
                    if ($platform->file_exists("$base/layouts")) {
1074
1152
                        $platform->recursiveRmDir("$base/layouts");
1075
1153
                    }
1076
 
                } else {
 
1154
                } else if (file_exists($base)) {
1077
1155
                    if ($platform->file_exists("$base/layouts")) {
1078
1156
                        $platform->rename("$base/layouts", "$base/themes");
1079
1157
                    } else {
1085
1163
            /* Removed parameters */
1086
1164
            foreach (array('language.selector', 'misc.login') as $paramName) {
1087
1165
                $ret = $module->removeParameter($paramName);
1088
 
                if ($ret->isError()) {
 
1166
                if ($ret) {
1089
1167
                    return $ret->wrap(__FILE__, __LINE__);
1090
1168
                }
1091
1169
            }
1098
1176
             */
1099
1177
            if (version_compare($currentVersion, '0.8.13', '<=')) {
1100
1178
                list ($ret, $themes) = GalleryCoreApi::fetchPluginStatus('theme');
1101
 
                if ($ret->isError()) {
 
1179
                if ($ret) {
1102
1180
                    return $ret->wrap(__FILE__, __LINE__);
1103
1181
                }
1104
1182
 
1106
1184
                    $gallery->guaranteeTimeLimit(30);
1107
1185
                    if (!empty($themeStatus['active'])) {
1108
1186
                        list($ret, $theme) = GalleryCoreApi::loadPlugin('theme', $themeId);
1109
 
                        if ($ret->isError() &&
 
1187
                        if ($ret &&
1110
1188
                            !($ret->getErrorCode() & ERROR_PLUGIN_VERSION_MISMATCH)) {
1111
1189
                            return $ret->wrap(__FILE__, __LINE__);
1112
1190
                        }
1113
1191
 
1114
1192
                        $ret = $theme->installOrUpgrade();
1115
 
                        if ($ret->isError()) {
 
1193
                        if ($ret) {
1116
1194
                            return $ret->wrap(__FILE__, __LINE__);
1117
1195
                        }
1118
1196
 
1119
 
                        list ($ret, $ignored) = $theme->activate();
1120
 
                        if ($ret->isError() &&
 
1197
                        list ($ret, $ignored) = $theme->activate(false);
 
1198
                        if ($ret &&
1121
1199
                            !($ret->getErrorCode() & ERROR_PLUGIN_VERSION_MISMATCH)) {
1122
1200
                            /*
1123
1201
                             * Theme getSettings may try to load ImageFrame interface, but
1131
1209
 
1132
1210
        case '0.9.30':
1133
1211
            /* Removed layout column from AlbumItem; matrix is only theme for now: set default */
 
1212
            $ret = $storage->configureStore($module->getId(), array('GalleryAlbumItem:1.0'));
 
1213
            if ($ret) {
 
1214
                return $ret->wrap(__FILE__, __LINE__);
 
1215
            }
 
1216
 
1134
1217
            $ret = $module->setParameter('default.theme', 'matrix');
1135
 
            if ($ret->isError()) {
 
1218
            if ($ret) {
1136
1219
                return $ret->wrap(__FILE__, __LINE__);
1137
1220
            }
1138
1221
            $ret = $module->removeParameter('default.layout');
1139
 
            if ($ret->isError()) {
 
1222
            if ($ret) {
1140
1223
                return $ret->wrap(__FILE__, __LINE__);
1141
1224
            }
1142
1225
            $query = '
1146
1229
              [::theme] = NULL
1147
1230
            ';
1148
1231
            $ret = $storage->execute($query);
1149
 
            if ($ret->isError()) {
 
1232
            if ($ret) {
1150
1233
                return $ret->wrap(__FILE__, __LINE__);
1151
1234
            }
1152
1235
 
1162
1245
            foreach (array('format.date' => '%x', 'format.time' => '%X', 'format.datetime' => '%c')
1163
1246
                     as $key => $value) {
1164
1247
                $ret = $module->setParameter($key, $value);
1165
 
                if ($ret->isError()) {
 
1248
                if ($ret) {
1166
1249
                    return $ret->wrap(__FILE__, __LINE__);
1167
1250
                }
1168
1251
            }
1181
1264
                $gallery->guaranteeTimeLimit(60);
1182
1265
                $ret = $statusMonitor->renderStatusMessage(
1183
1266
                    $module->translate('Clearing fast-download cache'), '', $i / 10);
1184
 
                if ($ret->isError()) {
 
1267
                if ($ret) {
1185
1268
                    return $ret->wrap(__FILE__, __LINE__);
1186
1269
                }
1187
1270
                for ($j = 0; $j < 10; $j++) {
1198
1281
            }
1199
1282
            $ret = $statusMonitor->renderStatusMessage(
1200
1283
                $module->translate('Clearing fast-download cache'), '', 1);
1201
 
            if ($ret->isError()) {
 
1284
            if ($ret) {
1202
1285
                return $ret->wrap(__FILE__, __LINE__);
1203
1286
            }
1204
1287
 
1206
1289
            /* 2.0 Release! */
1207
1290
 
1208
1291
        case '1.0.0':
 
1292
        case '1.0.0.x':
 
1293
            /* Schema only upgrade */
 
1294
            $ret = $storage->configureStore($module->getId(),
 
1295
                                            array('GalleryPluginParameterMap:1.2'));
 
1296
            if ($ret) {
 
1297
                return $ret->wrap(__FILE__, __LINE__);
 
1298
            }
 
1299
 
 
1300
        case '1.0.1':
 
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);
 
1305
                if ($ret) {
 
1306
                    return $ret->wrap(__FILE__, __LINE__);
 
1307
                }
 
1308
            }
 
1309
 
 
1310
        case '1.0.2':
1209
1311
            /* Security fix */
1210
1312
 
1211
 
        case '1.0.0.1':
 
1313
        case '1.0.3':
 
1314
            /* Consolidated .sql files into schema.tpl */
 
1315
 
 
1316
        case '1.0.4':
 
1317
            /* Added maintenance mode */
 
1318
 
 
1319
        case '1.0.5':
 
1320
            /* Remove plugins directory from g2data. */
 
1321
            $pluginDirectory = $gallery->getConfig('data.gallery.base') . 'plugins';
 
1322
            $pluginDirectories = array($pluginDirectory . '/modules',
 
1323
                                       $pluginDirectory . '/themes',
 
1324
                                       $pluginDirectory);
 
1325
 
 
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);
 
1330
                }
 
1331
            }
 
1332
 
 
1333
        case '1.0.6':
 
1334
            /* Add PluginPackageMap table */
 
1335
 
 
1336
        case '1.0.7':
 
1337
            $ret = $module->setParameter('exec.beNice', '0');
 
1338
            if ($ret) {
 
1339
                return $ret->wrap(__FILE__, __LINE__);
 
1340
            }
 
1341
 
 
1342
        case '1.0.8':
 
1343
        case '1.0.9':
1212
1344
            /* Security fix in zipcart */
1213
1345
 
 
1346
        case '1.0.10':
 
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)');
 
1350
                $query = sprintf('
 
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);
 
1358
            }
 
1359
 
 
1360
            /*
 
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.
 
1364
             */
 
1365
            $ret = $storage->configureStore($module->getId(),
 
1366
                                            array('GalleryAccessMap:1.0', 'GalleryUser:1.0'));
 
1367
            if ($ret) {
 
1368
                return $ret->wrap(__FILE__, __LINE__);
 
1369
            }
 
1370
 
 
1371
            /* If coming from 0.9.5 or earlier then GalleryAccessMap already has userOrGroupId */
 
1372
            if (version_compare($currentVersion, '0.9.5', '>')) {
 
1373
                $query = '
 
1374
                UPDATE
 
1375
                  [GalleryAccessMap]
 
1376
                SET
 
1377
                  [::userOrGroupId] = [::userId] + [::groupId]
 
1378
                ';
 
1379
                $ret = $storage->execute($query, array());
 
1380
                if ($ret) {
 
1381
                    return $ret->wrap(__FILE__, __LINE__);
 
1382
                }
 
1383
            }
 
1384
 
 
1385
            $ret = $storage->configureStore($module->getId(), array('GalleryAccessMap:1.1'));
 
1386
            if ($ret) {
 
1387
                return $ret->wrap(__FILE__, __LINE__);
 
1388
            }
 
1389
 
 
1390
            list ($ret, $flagModifier) =
 
1391
                $storage->getFunctionSql('BITAND', array('[::flags]', '?'));
 
1392
            if ($ret) {
 
1393
                return $ret->wrap(__FILE__, __LINE__);
 
1394
            }
 
1395
            $query = '
 
1396
            UPDATE
 
1397
              [GalleryPermissionSetMap]
 
1398
            SET
 
1399
              [::flags] = ' . $flagModifier . '
 
1400
            ';
 
1401
            $ret = $storage->execute($query, array(3));
 
1402
            if ($ret) {
 
1403
                return $ret->wrap(__FILE__, __LINE__);
 
1404
            }
 
1405
 
 
1406
        case '1.0.11':
 
1407
            /* Several previous upgrades used 'modules' instead of 'module' with plugin params */
 
1408
            list ($ret, $coreParams) = $module->fetchParameters();
 
1409
            if ($ret) {
 
1410
                return $ret->wrap(__FILE__, __LINE__);
 
1411
            }
 
1412
            foreach (array('misc.useShortUrls', 'language.selector') as $key) {
 
1413
                if (isset($coreParams[$key])) {
 
1414
                    $ret = $module->removeParameter('misc.useShortUrls');
 
1415
                    if ($ret) {
 
1416
                        return $ret->wrap(__FILE__, __LINE__);
 
1417
                    }
 
1418
                }
 
1419
            }
 
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);
 
1425
                    if ($ret) {
 
1426
                        return $ret->wrap(__FILE__, __LINE__);
 
1427
                    }
 
1428
                }
 
1429
            }
 
1430
            $ret = GalleryCoreApi::removeMapEntry(
 
1431
                'GalleryPluginParameterMap', array('pluginType' => 'modules'));
 
1432
            if ($ret) {
 
1433
                return $ret->wrap(__FILE__, __LINE__);
 
1434
            }
 
1435
 
 
1436
        case '1.0.12':
 
1437
            /* Add param 'language.useBrowserPref' */
 
1438
            list ($ret, $langCode) = $module->getParameter('default.language');
 
1439
            if ($ret) {
 
1440
                return $ret->wrap(__FILE__, __LINE__);
 
1441
            }
 
1442
            $useBrowserPref = '0';
 
1443
            if (empty($langCode)) {
 
1444
                $useBrowserPref = '1';
 
1445
                $ret = $module->setParameter('default.language', 'en_US');
 
1446
                if ($ret) {
 
1447
                    return $ret->wrap(__FILE__, __LINE__);
 
1448
                }
 
1449
            }
 
1450
            $ret = $module->setParameter('language.useBrowserPref', $useBrowserPref);
 
1451
            if ($ret) {
 
1452
                return $ret->wrap(__FILE__, __LINE__);
 
1453
            }
 
1454
 
 
1455
        case '1.0.13':
 
1456
            /* Add config parameter: 'baseUri'*/
 
1457
        case '1.0.14':
 
1458
            /* GalleryCoreApi 7.0 and GalleryModule 3.0 */
 
1459
        case '1.0.15':
 
1460
            /*
 
1461
             * Add fast-download for GalleryDataItems too. Fast-download files are now in
 
1462
             * cache/entity/. Delete the old files in cache/derivative/.
 
1463
             */
 
1464
            $gallery->guaranteeTimeLimit(60);
 
1465
            $query = 'SELECT [GalleryDerivativeImage::id]
 
1466
                      FROM [GalleryDerivativeImage]';
 
1467
            list ($ret, $searchResults) = $gallery->search($query);
 
1468
            if ($ret) {
 
1469
                return $ret->wrap(__FILE__, __LINE__);
 
1470
            }
 
1471
 
 
1472
            if ($searchResults->resultCount() > 0) {
 
1473
                $derivativeIds = array();
 
1474
                while ($result = $searchResults->nextResult()) {
 
1475
                    $derivativeIds[] = $result[0];
 
1476
                }
 
1477
                $totalDerivatives = count($derivativeIds);
 
1478
                $base = $gallery->getConfig('data.gallery.cache');
 
1479
                $gallery->guaranteeTimeLimit(60);
 
1480
 
 
1481
                /* Show a progress bar */
 
1482
                $ret = $statusMonitor->renderStatusMessage(
 
1483
                    $module->translate('Deleting old fast-download cache'), '', 0);
 
1484
                if ($ret) {
 
1485
                    return $ret->wrap(__FILE__, __LINE__);
 
1486
                }
 
1487
 
 
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);
 
1496
                    }
 
1497
 
 
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);
 
1504
                        if ($ret) {
 
1505
                            return $ret->wrap(__FILE__, __LINE__);
 
1506
                        }
 
1507
                    }
 
1508
                }
 
1509
            }
 
1510
        case '1.0.16':
 
1511
            /* Added 'not-null' to Entities.inc and Map.inc */
 
1512
            $storageExtras =& $storage->_getExtras();
 
1513
            $storageExtras->_clearEntityAndMapCache();
 
1514
        case '1.0.17':
 
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);
 
1519
                if ($ret) {
 
1520
                    return $ret->wrap(__FILE__, __LINE__);
 
1521
                }
 
1522
            }
 
1523
 
 
1524
        case '1.0.18':
 
1525
            /* Add index to GalleryEntity::linkId */
 
1526
            $ret = $storage->configureStore($module->getId(), array('GalleryEntity:1.1'));
 
1527
            if ($ret) {
 
1528
                return $ret->wrap(__FILE__, __LINE__);
 
1529
            }
 
1530
 
 
1531
        case '1.0.19':
 
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);
 
1537
            if ($ret) {
 
1538
                return $ret->wrap(__FILE__, __LINE__);
 
1539
            }
 
1540
 
 
1541
        case '1.0.20':
 
1542
            /* Add configurable captcha security level */
 
1543
            $ret = GalleryCoreApi::setPluginParameter('module', 'core', 'captcha.level', 'MEDIUM');
 
1544
            if ($ret) {
 
1545
                return $ret->wrap(__FILE__, __LINE__);
 
1546
            }
 
1547
 
 
1548
        case '1.0.21':
 
1549
            /* GallerySession change: Store sessions in the database and no longer on disk */
 
1550
            $sessionsDir = $gallery->getConfig('data.gallery.base') . 'sessions' .
 
1551
                $platform->getDirectorySeparator();
 
1552
            $stepSize = 100;
 
1553
            $count = 0;
 
1554
            $iterationSize = 5000;
 
1555
            $iteration = 1;
 
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)),
 
1560
                '', 0);
 
1561
            if ($ret) {
 
1562
                return $ret->wrap(__FILE__, __LINE__);
 
1563
            }
 
1564
            $dir = $platform->opendir($sessionsDir, 'r');
 
1565
            if (!$dir) {
 
1566
                return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__,
 
1567
                                             "Can't access session dir");
 
1568
            }
 
1569
            $gallery->guaranteeTimeLimit(60);
 
1570
            while (($filename = $platform->readdir($dir)) !== false) {
 
1571
                if ($filename == '.' || $filename == '..') {
 
1572
                    continue;
 
1573
                }
 
1574
                $count++;
 
1575
                $platform->unlink($sessionsDir . $filename);
 
1576
 
 
1577
                /* Update the progress bar / prevent timouts */
 
1578
                if ($count % $stepSize == 0) {
 
1579
                    $gallery->guaranteeTimeLimit(60);
 
1580
                    $ret = $statusMonitor->renderStatusMessage(
 
1581
                        $module->translate(
 
1582
                            array('text' => 'Deleting old session files (iteration %d)',
 
1583
                                  'arg1' => $iteration)),
 
1584
                        '', $count / $iterationSize);
 
1585
                    if ($ret) {
 
1586
                        return $ret->wrap(__FILE__, __LINE__);
 
1587
                    }
 
1588
                }
 
1589
 
 
1590
                if ($count > $iterationSize) {
 
1591
                    $iteration++;
 
1592
                    $count = 0;
 
1593
                }
 
1594
            }
 
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)),
 
1600
                '', 1);
 
1601
            if ($ret) {
 
1602
                return $ret->wrap(__FILE__, __LINE__);
 
1603
            }
 
1604
 
 
1605
        case '1.0.22':
 
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;
 
1667
                    $query = sprintf('
 
1668
                    ALTER TABLE `%s%s`
 
1669
                    DROP INDEX `%s%s`,
 
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);
 
1675
                }
 
1676
                $gallery->debug('Finished renaming unnamed pre-beta-3 indices to named indices');
 
1677
            }
 
1678
 
 
1679
            /* Commit transactions before we execute a query that we expect to fail */
 
1680
            $ret = $storage->checkPoint();
 
1681
            if ($ret) {
 
1682
                return $ret->wrap(__FILE__, __LINE__);
 
1683
            }
 
1684
 
 
1685
            /*
 
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.
 
1688
             */
 
1689
            $gallery->debug('Adding an index to the AccessMap table, ignore errors');
 
1690
            $storage->configureStore($module->getId(), array('GalleryAccessMap:1.2'));
 
1691
 
 
1692
            /* Postgres will abort the transaction if the index exists, so checkpoint here. */
 
1693
            $ret = $storage->checkpoint();
 
1694
            if ($ret) {
 
1695
                return $ret->wrap(__FILE__, __LINE__);
 
1696
            }
 
1697
 
 
1698
            $gallery->debug('Finished adding an index to the AccessMap table');
 
1699
            /*
 
1700
             * Make sure the schema update is stored, can't use updateMapEntry because Schema is
 
1701
             * not in Maps.xml
 
1702
             */
 
1703
            $query = sprintf('
 
1704
            UPDATE %sSchema
 
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);
 
1711
            if ($ret) {
 
1712
                return $ret->wrap(__FILE__, __LINE__);
 
1713
            }
 
1714
 
 
1715
        case '1.0.23':
 
1716
            /* Rename GalleryCache to GalleryCacheMap, and make the value column TEXT(LARGE) */
 
1717
 
 
1718
        case '1.0.24':
 
1719
            /* Add CoreCaptchaAdminOption, rename level parameter */
 
1720
            $gallery->guaranteeTimeLimit(60);
 
1721
            list ($ret, $level) = $module->getParameter('captcha.level');
 
1722
            if ($ret) {
 
1723
                return $ret->wrap(__FILE__, __LINE__);
 
1724
            }
 
1725
            $ret = $module->setParameter('validation.level', $level);
 
1726
            if ($ret) {
 
1727
                return $ret->wrap(__FILE__, __LINE__);
 
1728
            }
 
1729
            $ret = $module->removeParameter('captcha.level');
 
1730
            if ($ret) {
 
1731
                return $ret->wrap(__FILE__, __LINE__);
 
1732
            }
 
1733
 
 
1734
        case '1.0.25':
 
1735
        case '1.0.26':
 
1736
            /* 2.1 Release Candidate 1! */
 
1737
 
 
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 . '`');
 
1746
                    if ($ret) {
 
1747
                        return $ret->wrap(__FILE__, __LINE__);
 
1748
                    }
 
1749
                    $row = $results->nextResult();
 
1750
                    $result = $row[1];
 
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);
 
1755
                        if ($ret) {
 
1756
                            return $ret->wrap(__FILE__, __LINE__);
 
1757
                        }
 
1758
                        $gallery->guaranteeTimeLimit(120);
 
1759
                        $storageExtras =& $storage->_getExtras();
 
1760
                        list ($ret, $tableVersions) = $storageExtras->_loadTableVersions();
 
1761
                        if ($ret) {
 
1762
                            return $ret->wrap(__FILE__, __LINE__);
 
1763
                        }
 
1764
                        $types = array('varchar'  => 'varbinary',
 
1765
                                       'text'     => 'blob',
 
1766
                                       'longtext' => 'longblob');
 
1767
                        $i = 0;
 
1768
                        foreach ($tableVersions as $tableName => $unused) {
 
1769
                            $i++;
 
1770
                            $tableName = $storage->_tablePrefix . $tableName;
 
1771
                            /* First the table itself */
 
1772
                            $query = "ALTER TABLE `$tableName` DEFAULT CHARACTER SET utf8";
 
1773
                            $ret = $storage->execute($query);
 
1774
                            if ($ret) {
 
1775
                                return $ret->wrap(__FILE__, __LINE__);
 
1776
                            }
 
1777
                            /*
 
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
 
1784
                             */
 
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);
 
1789
                            if ($ret) {
 
1790
                                return $ret->wrap(__FILE__, __LINE__);
 
1791
                            }
 
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])) {
 
1797
                                    continue;
 
1798
                                }
 
1799
                                $change =
 
1800
                                    'CHANGE `' . $column['Field'] . '` `' . $column['Field'] . '` ';
 
1801
                                $binaryType = preg_replace('/'. $type .'/i', $types[$type],
 
1802
                                                           $column['Type']);
 
1803
                                $attributes = ' ';
 
1804
                                if ($column['Default'] == 'NULL') {
 
1805
                                    $attributes .= 'DEFAULT NULL ';
 
1806
                                } else if (!empty($column['Default'])) {
 
1807
                                    $attributes .= 'DEFAULT ' . $column['Default'] . ' ';
 
1808
                                }
 
1809
                                $attributes .= $column['Null'] == 'YES' ? 'NULL' : 'NOT NULL';
 
1810
                                $changeToBinary[] = $change . $binaryType . $attributes;
 
1811
                                $changeToUtf8[] =
 
1812
                                    $change . $column['Type'] . ' CHARACTER SET utf8' . $attributes;
 
1813
                            }
 
1814
                            if (count($changeToBinary)) {
 
1815
                                $query =
 
1816
                                    "ALTER TABLE `$tableName` " . implode(', ', $changeToBinary);
 
1817
                                $ret = $storage->Execute($query);
 
1818
                                if ($ret) {
 
1819
                                    return $ret->wrap(__FILE__, __LINE__);
 
1820
                                }
 
1821
                                $query = "ALTER TABLE `$tableName` " . implode(', ', $changeToUtf8);
 
1822
                                $ret = $storage->Execute($query);
 
1823
                                if ($ret) {
 
1824
                                    return $ret->wrap(__FILE__, __LINE__);
 
1825
                                }
 
1826
                            }
 
1827
 
 
1828
                            $ret = $statusMonitor->renderStatusMessage(
 
1829
                                $module->translate('Converting MySQL data to UTF8'),
 
1830
                                null, $i / count($tableVersions));
 
1831
                            if ($ret) {
 
1832
                                return $ret->wrap(__FILE__, __LINE__);
 
1833
                            }
 
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 */
 
1839
 
 
1840
            /* Clear the cache data since we changed the blob encoding */
 
1841
            $gallery->guaranteeTimeLimit(60);
 
1842
            $ret = GalleryCoreApi::removeAllMapEntries('GalleryCacheMap');
 
1843
            if ($ret) {
 
1844
                return $ret->wrap(__FILE__, __LINE__);
 
1845
            }
 
1846
 
 
1847
        case '1.0.27':
 
1848
        case '1.0.28':
 
1849
            /* Change in page cache key format */
 
1850
        case '1.0.29':
 
1851
            /* Support for transactional locking */
 
1852
 
 
1853
        case '1.0.30':
 
1854
            /* Pull dangerous mime types */
 
1855
            $ret = GalleryCoreApi::removeMimeType(
 
1856
                array('mimeType' => array('text/html', 'application/xhtml+xml', 'text/xml')));
 
1857
            if ($ret) {
 
1858
                return $ret->wrap(__FILE__, __LINE__);
 
1859
            }
 
1860
 
 
1861
        case '1.0.31':
 
1862
            list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'core');
 
1863
            if ($ret) {
 
1864
                return $ret->wrap(__FILE__, __LINE__);
 
1865
            }
 
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]);
 
1871
                    if ($ret) {
 
1872
                        return $ret->wrap(__FILE__, __LINE__);
 
1873
                    }
 
1874
                }
 
1875
            }
 
1876
 
 
1877
        case '1.0.32':
 
1878
            /* 2.1 Release Candidate 2! */
 
1879
        case '1.0.33':
 
1880
            /* Security fix in installer/upgrader - RC-2a */
 
1881
        case '1.0.34':
 
1882
            /* 2.1 Release! */
 
1883
        case '1.1.0':
 
1884
            /* 2.1.1 Bugfix Release */
 
1885
 
1214
1886
        case 'end of upgrade path':
1215
1887
            /*
1216
1888
             * Leave this bogus case at the end of the legitimate case statements so that we
1220
1892
 
1221
1893
        default:
1222
1894
            $gallery->debug('Error: Unknown module version');
1223
 
            return GalleryStatus::error(ERROR_BAD_PLUGIN, __FILE__, __LINE__,
 
1895
            return GalleryCoreApi::error(ERROR_BAD_PLUGIN, __FILE__, __LINE__,
1224
1896
                                        sprintf('Unknown module version %s', $currentVersion));
1225
1897
        }
1226
1898
 
1241
1913
 
1242
1914
        if ($versionDatError) {
1243
1915
            $gallery->debug('Error: Can\'t write to versions file');
1244
 
            return GalleryStatus::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__,
 
1916
            return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__,
1245
1917
                                        'Can\'t write to the versions file');
1246
1918
        }
1247
1919
 
1248
 
        return GalleryStatus::success();
 
1920
        return null;
1249
1921
    }
1250
1922
 
1251
1923
    /**
1260
1932
        global $gallery;
1261
1933
        $configChanges = array();
1262
1934
 
 
1935
        if (substr($currentVersion, 0, 6) == '1.0.0.') {
 
1936
            $currentVersion = '1.0.0.x';
 
1937
        }
 
1938
 
1263
1939
        /**
1264
1940
         * README: How to update the block below.
1265
1941
         *
1330
2006
 
1331
2007
            $configChanges[] = array(
1332
2008
                'remove' => array('{/\*[^/]*\*/\s*\$gallery->setConfig\(\'galleryId\',.*?;\s*}s'),
1333
 
                'add' => $add);
 
2009
                'add' => $add, 'edit' => array());
1334
2010
 
1335
2011
        case '0.9.20':
1336
2012
        case '0.9.21':
1356
2032
 */
1357
2033
$gallery->setConfig(\'cookieId\', \'' . $cookieId . '\');
1358
2034
';
1359
 
            $configChanges[] = array('remove' => array(), 'add' => $add);
 
2035
            $configChanges[] = array('remove' => array(), 'add' => $add, 'edit' => array());
1360
2036
 
1361
2037
        case '0.9.22':
1362
2038
        case '0.9.23':
1363
2039
            /* Session cookie change, revert the last change and try something new */
1364
2040
            $configChanges[] = array(
1365
2041
                'remove' => array('{/\*[^/]*\*/\s*\$gallery->setConfig\(\'cookieId\',.*?;\s*}s'),
1366
 
                'add' => array());
 
2042
                'add' => array(), 'edit' => array());
1367
2043
 
1368
2044
        case '0.9.24':
1369
2045
        case '0.9.25':
1380
2056
        case '0.9.36':
1381
2057
        case '0.9.37':
1382
2058
        case '1.0.0':
1383
 
        case '1.0.0.1':
 
2059
        case '1.0.0.x':
 
2060
        case '1.0.1':
 
2061
        case '1.0.2':
 
2062
        case '1.0.3':
 
2063
 
 
2064
        case '1.0.4':
 
2065
            $configChanges[] = array('remove' => array(), 'edit' => array(), 'add' => array(
 
2066
'
 
2067
/*
 
2068
 * Maintenance mode.  You can disable access to the site for anyone but
 
2069
 * site administrators by setting this this flag.  Set value below to:
 
2070
 *  true (without quotes) - to use a basic notification page; themed
 
2071
 *    view with admin login link when codebase is up to date, but a
 
2072
 *    plain unstyled page when codebase has been updated but upgrader
 
2073
 *    has not yet been run.
 
2074
 *  url (with quotes) - provide a url where requests are redirected in
 
2075
 *    either case described above.  Example: \'/maintenance.html\'
 
2076
 */
 
2077
$gallery->setConfig(\'mode.maintenance\', false);
 
2078
'));
 
2079
 
 
2080
        case '1.0.5':
 
2081
        case '1.0.6':
 
2082
        case '1.0.7':
 
2083
        case '1.0.8':
 
2084
        case '1.0.9':
 
2085
        case '1.0.10':
 
2086
        case '1.0.11':
 
2087
        case '1.0.12':
 
2088
        case '1.0.13':
 
2089
            /* Add config parameter: 'baseUri'*/
 
2090
            $add[] =
 
2091
'
 
2092
/*
 
2093
 * This setting can be used to override Gallery\'s auto-detection of the domain-name,
 
2094
 * protocol (http/https), URL path, and of the file & query string.
 
2095
 * Most users can leave this empty. If the server is misconfigured or for very special
 
2096
 * setups, this setting can be quite handy.
 
2097
 * Examples (the positions of the slashes (\'/\') are important):
 
2098
 *   override the path: $gallery->setConfig(\'baseUri\', \'/another/path/\');
 
2099
 *   override the host + path: $gallery->setConfig(\'baseUri\', \'example.com/gallery2/\');
 
2100
 *   override the protocol + host + path + file:
 
2101
 *           $gallery->setConfig(\'baseUri\', \'https://example.com:8080/gallery2/index.php\');
 
2102
 */
 
2103
$gallery->setConfig(\'baseUri\', \'\');';
 
2104
 
 
2105
            $configChanges[] = array('remove' => array(), 'add' => $add, 'edit' => array());
 
2106
 
 
2107
        case '1.0.14':
 
2108
        case '1.0.15':
 
2109
            /*
 
2110
             * Normalize the config path 'data.gallery.base' (add a trailing slash if necessary)
 
2111
             * Escape the backslashes and quotes two times since we feed preg_replace with it
 
2112
             */
 
2113
            $tmp = strtr($gallery->getConfig('data.gallery.base'),
 
2114
                         array('\\' => '\\\\\\\\', "'" => "\\\\'"));
 
2115
            $edit['regexp'] = '{\$gallery->setConfig\(\'data\.gallery\.base\',.*?;}s';
 
2116
            $edit['replacement'] = '$gallery->setConfig(\'data.gallery.base\', \'' . $tmp . '\');';
 
2117
            $configChanges[] = array('remove' => array(), 'add' => array(), 'edit' => array($edit));
 
2118
        case '1.0.16':
 
2119
        case '1.0.17':
 
2120
        case '1.0.18':
 
2121
        case '1.0.19':
 
2122
        case '1.0.20':
 
2123
        case '1.0.21':
 
2124
        case '1.0.22':
 
2125
        case '1.0.23':
 
2126
        case '1.0.24':
 
2127
        case '1.0.25':
 
2128
        case '1.0.26':
 
2129
        case '1.0.27':
 
2130
        case '1.0.28':
 
2131
        case '1.0.29':
 
2132
        case '1.0.30':
 
2133
        case '1.0.31':
 
2134
        case '1.0.32':
 
2135
        case '1.0.33':
 
2136
        case '1.0.34':
 
2137
        case '1.1.0':
1384
2138
 
1385
2139
        case 'end of upgrade path':
1386
2140
            /*
1415
2169
     */
1416
2170
    function performConfigUpgrade($currentVersion) {
1417
2171
        global $gallery;
1418
 
        $platform = $gallery->getPlatform();
 
2172
        $platform =& $gallery->getPlatform();
1419
2173
 
1420
2174
        $configFilePath = GALLERY_CONFIG_DIR . '/config.php';
1421
2175
        $configContents = implode('', $platform->file($configFilePath));
1422
2176
        if (empty($configContents) || strlen($configContents) < 100) {
1423
 
            return GalleryStatus::error(ERROR_MISSING_VALUE, __FILE__, __LINE__,
 
2177
            return GalleryCoreApi::error(ERROR_MISSING_VALUE, __FILE__, __LINE__,
1424
2178
                                        'Unable to read current config.php contents');
1425
2179
        }
1426
2180
 
1429
2183
            foreach ($change['remove'] as $regexp) {
1430
2184
                $configContents = preg_replace($regexp, '', $configContents);
1431
2185
            }
 
2186
            foreach ($change['edit'] as $edit) {
 
2187
                $configContents =
 
2188
                    preg_replace($edit['regexp'], $edit['replacement'], $configContents);
 
2189
            }
1432
2190
            foreach ($change['add'] as $content) {
1433
2191
                $configContents = preg_replace('{\?>\s*\z}', $content . "\n?>\n", $configContents);
1434
2192
            }
1435
2193
        }
1436
2194
 
1437
2195
        if (!$out = $platform->fopen($configFilePath, 'w')) {
1438
 
            return GalleryStatus::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__,
 
2196
            return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__,
1439
2197
                                        'Unable to write to config.php');
1440
2198
        }
1441
2199
        if ($platform->fwrite($out, $configContents) < strlen($configContents)) {
1442
 
            return GalleryStatus::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__,
 
2200
            return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__,
1443
2201
                                        'Unable to write config.php contents');
1444
2202
        }
1445
2203
        $platform->fclose($out);
1446
2204
 
1447
 
        return GalleryStatus::success();
 
2205
        return null;
1448
2206
    }
1449
2207
 
1450
2208
    /**
1458
2216
        global $gallery;
1459
2217
 
1460
2218
        list ($ret, $id) = $module->getParameter('id.allUserGroup');
1461
 
        if ($ret->isError()) {
 
2219
        if ($ret) {
1462
2220
            return $ret->wrap(__FILE__, __LINE__);
1463
2221
        }
1464
2222
 
1465
2223
        if (!empty($id)) {
1466
 
            return GalleryStatus::success();
 
2224
            return null;
1467
2225
        }
1468
2226
 
1469
 
        GalleryCoreApi::relativeRequireOnce('modules/core/classes/GalleryGroup.class');
 
2227
        GalleryCoreApi::requireOnce('modules/core/classes/GalleryGroup.class');
1470
2228
        $group = new GalleryGroup();
1471
2229
 
1472
2230
        $groupName = $module->translate('Registered Users');
1473
2231
        $ret = $group->create($groupName, GROUP_ALL_USERS);
1474
 
        if ($ret->isError()) {
 
2232
        if ($ret) {
1475
2233
            return $ret->wrap(__FILE__, __LINE__);
1476
2234
        }
1477
2235
 
1478
2236
        $ret = $group->save();
1479
 
        if ($ret->isError()) {
 
2237
        if ($ret) {
1480
2238
            return $ret->wrap(__FILE__, __LINE__);
1481
2239
        }
1482
2240
 
1483
2241
        $ret = $module->setParameter('id.allUserGroup', $group->getId());
1484
 
        if ($ret->isError()) {
 
2242
        if ($ret) {
1485
2243
            return $ret->wrap(__FILE__, __LINE__);
1486
2244
        }
1487
2245
 
1488
 
        return GalleryStatus::success();
 
2246
        return null;
1489
2247
    }
1490
2248
 
1491
2249
    /**
1499
2257
        global $gallery;
1500
2258
 
1501
2259
        list ($ret, $id) = $module->getParameter('id.adminGroup');
1502
 
        if ($ret->isError()) {
 
2260
        if ($ret) {
1503
2261
            return $ret->wrap(__FILE__, __LINE__);
1504
2262
        }
1505
2263
 
1506
2264
        if (!empty($id)) {
1507
 
            return GalleryStatus::success();
 
2265
            return null;
1508
2266
        }
1509
2267
 
1510
 
        GalleryCoreApi::relativeRequireOnce('modules/core/classes/GalleryGroup.class');
 
2268
        GalleryCoreApi::requireOnce('modules/core/classes/GalleryGroup.class');
1511
2269
        $group = new GalleryGroup();
1512
2270
 
1513
2271
        $groupName = $module->translate('Site Admins');
1514
2272
        $ret = $group->create($groupName, GROUP_SITE_ADMINS);
1515
 
        if ($ret->isError()) {
 
2273
        if ($ret) {
1516
2274
            return $ret->wrap(__FILE__, __LINE__);
1517
2275
        }
1518
2276
 
1519
2277
        $ret = $group->save();
1520
 
        if ($ret->isError()) {
 
2278
        if ($ret) {
1521
2279
            return $ret->wrap(__FILE__, __LINE__);
1522
2280
        }
1523
2281
 
1524
2282
        $ret = $module->setParameter('id.adminGroup', $group->getId());
1525
 
        if ($ret->isError()) {
 
2283
        if ($ret) {
1526
2284
            return $ret->wrap(__FILE__, __LINE__);
1527
2285
        }
1528
2286
 
1529
 
        return GalleryStatus::success();
 
2287
        return null;
1530
2288
    }
1531
2289
 
1532
2290
    /**
1540
2298
        global $gallery;
1541
2299
 
1542
2300
        list ($ret, $id) = $module->getParameter('id.everybodyGroup');
1543
 
        if ($ret->isError()) {
 
2301
        if ($ret) {
1544
2302
            return $ret->wrap(__FILE__, __LINE__);
1545
2303
        }
1546
2304
 
1547
2305
        if (!empty($id)) {
1548
 
            return GalleryStatus::success();
 
2306
            return null;
1549
2307
        }
1550
2308
 
1551
 
        GalleryCoreApi::relativeRequireOnce('modules/core/classes/GalleryGroup.class');
 
2309
        GalleryCoreApi::requireOnce('modules/core/classes/GalleryGroup.class');
1552
2310
        $group = new GalleryGroup();
1553
2311
 
1554
2312
        $groupName = $module->translate('Everybody');
1555
2313
        $ret = $group->create($groupName, GROUP_EVERYBODY);
1556
 
        if ($ret->isError()) {
 
2314
        if ($ret) {
1557
2315
            return $ret->wrap(__FILE__, __LINE__);
1558
2316
        }
1559
2317
 
1560
2318
        $ret = $group->save();
1561
 
        if ($ret->isError()) {
 
2319
        if ($ret) {
1562
2320
            return $ret->wrap(__FILE__, __LINE__);
1563
2321
        }
1564
2322
 
1565
2323
        $ret = $module->setParameter('id.everybodyGroup', $group->getId());
1566
 
        if ($ret->isError()) {
 
2324
        if ($ret) {
1567
2325
            return $ret->wrap(__FILE__, __LINE__);
1568
2326
        }
1569
2327
 
1570
 
        return GalleryStatus::success();
 
2328
        return null;
1571
2329
    }
1572
2330
 
1573
2331
    /**
1581
2339
        global $gallery;
1582
2340
 
1583
2341
        list ($ret, $id) = $module->getParameter('id.anonymousUser');
1584
 
        if ($ret->isError()) {
 
2342
        if ($ret) {
1585
2343
            return $ret->wrap(__FILE__, __LINE__);
1586
2344
        }
1587
2345
 
1588
2346
        if (!empty($id)) {
1589
 
            return GalleryStatus::success();
 
2347
            return null;
1590
2348
        }
1591
2349
 
1592
 
        GalleryCoreApi::relativeRequireOnce('modules/core/classes/GalleryUser.class');
 
2350
        GalleryCoreApi::requireOnce('modules/core/classes/GalleryUser.class');
1593
2351
        $user = new GalleryUser();
1594
2352
 
1595
2353
        $userName = 'guest';
1596
2354
        $fullName = $module->translate('Guest');
1597
2355
        $ret = $user->create($userName);
1598
 
        if ($ret->isError()) {
 
2356
        if ($ret) {
1599
2357
            return $ret->wrap(__FILE__, __LINE__);
1600
2358
        }
1601
2359
        $user->setFullName($fullName);
1602
2360
        $user->changePassword('');
1603
2361
 
1604
2362
        $ret = $user->save();
1605
 
        if ($ret->isError()) {
 
2363
        if ($ret) {
1606
2364
            return $ret->wrap(__FILE__, __LINE__);
1607
2365
        }
1608
2366
 
1609
2367
        /* Remove the anonymous user from the "all users" group */
1610
2368
        list ($ret, $allUserGroupId) = $module->getParameter('id.allUserGroup');
1611
 
        if ($ret->isError()) {
 
2369
        if ($ret) {
1612
2370
            return $ret->wrap(__FILE__, __LINE__);
1613
2371
        }
1614
2372
 
1615
2373
        GalleryCoreApi::removeUserFromGroup($user->getId(), $allUserGroupId);
1616
2374
 
1617
2375
        $ret = $module->setParameter('id.anonymousUser', $user->getId());
1618
 
        if ($ret->isError()) {
 
2376
        if ($ret) {
1619
2377
            return $ret->wrap(__FILE__, __LINE__);
1620
2378
        }
1621
2379
 
1622
 
        return GalleryStatus::success();
 
2380
        return null;
1623
2381
    }
1624
2382
 
1625
2383
    /**
1634
2392
 
1635
2393
        /* Don't create if there is already a user in the admin group */
1636
2394
        list ($ret, $adminGroupId) = $module->getParameter('id.adminGroup');
1637
 
        if ($ret->isError()) {
 
2395
        if ($ret) {
1638
2396
            return $ret->wrap(__FILE__, __LINE__);
1639
2397
        }
1640
2398
 
1641
2399
        list ($ret, $results) = GalleryCoreApi::fetchUsersForGroup($adminGroupId);
1642
 
        if ($ret->isError()) {
 
2400
        if ($ret) {
1643
2401
            return $ret->wrap(__FILE__, __LINE__);
1644
2402
        }
1645
2403
 
1646
2404
        if (sizeof($results) > 0) {
1647
 
            return GalleryStatus::success();
 
2405
            return null;
1648
2406
        }
1649
2407
 
1650
 
        GalleryCoreApi::relativeRequireOnce('modules/core/classes/GalleryUser.class');
 
2408
        GalleryCoreApi::requireOnce('modules/core/classes/GalleryUser.class');
1651
2409
        $user = new GalleryUser();
1652
2410
 
1653
2411
        /*
1659
2417
        $email = $gallery->getConfig('setup.admin.email');
1660
2418
        $fullName = $gallery->getConfig('setup.admin.fullName');
1661
2419
        $ret = $user->create($userName);
1662
 
        if ($ret->isError()) {
 
2420
        if ($ret) {
1663
2421
            return $ret->wrap(__FILE__, __LINE__);
1664
2422
        }
1665
2423
        $user->changePassword($gallery->getConfig('setup.password'));
1667
2425
        $user->setEmail($email);
1668
2426
 
1669
2427
        $ret = $user->save();
1670
 
        if ($ret->isError()) {
 
2428
        if ($ret) {
1671
2429
            return $ret->wrap(__FILE__, __LINE__);
1672
2430
        }
1673
2431
 
1674
2432
        /* Add her to the admin group */
1675
2433
        $ret = GalleryCoreApi::addUserToGroup($user->getId(), $adminGroupId);
1676
 
        if ($ret->isError()) {
 
2434
        if ($ret) {
1677
2435
            return $ret->wrap(__FILE__, __LINE__);
1678
2436
        }
1679
2437
 
1683
2441
         */
1684
2442
        $gallery->setActiveUser($user);
1685
2443
 
1686
 
        return GalleryStatus::success();
 
2444
        return null;
1687
2445
    }
1688
2446
 
1689
2447
    /**
1699
2457
        /* Do we already have a root? */
1700
2458
        list ($ret, $rootAlbumId) = $module->getParameter('id.rootAlbum');
1701
2459
        if ($rootAlbumId) {
1702
 
            return GalleryStatus::success();
 
2460
            return null;
1703
2461
        }
1704
2462
 
1705
 
        GalleryCoreApi::relativeRequireOnce('modules/core/classes/GalleryAlbumItem.class');
 
2463
        GalleryCoreApi::requireOnce('modules/core/classes/GalleryAlbumItem.class');
1706
2464
        $album = new GalleryAlbumItem();
1707
2465
 
1708
2466
        $ret = $album->createRoot();
1709
 
        if ($ret->isError()) {
 
2467
        if ($ret) {
1710
2468
            return $ret->wrap(__FILE__, __LINE__);
1711
2469
        }
1712
2470
        $title = $module->translate('Gallery');
1715
2473
        $album->setDescription($description);
1716
2474
 
1717
2475
        $ret = $album->save();
1718
 
        if ($ret->isError()) {
 
2476
        if ($ret) {
1719
2477
            return $ret->wrap(__FILE__, __LINE__);
1720
2478
        }
1721
2479
 
1722
2480
        /* Give everybody some permissions */
1723
2481
        list ($ret, $groupId) = $module->getParameter('id.everybodyGroup');
1724
 
        if ($ret->isError()) {
 
2482
        if ($ret) {
1725
2483
            return $ret->wrap(__FILE__, __LINE__);
1726
2484
        }
1727
2485
 
1728
2486
        $ret = GalleryCoreApi::addGroupPermission($album->getId(), $groupId, 'core.viewAll');
1729
 
        if ($ret->isError()) {
 
2487
        if ($ret) {
1730
2488
            return $ret->wrap(__FILE__, __LINE__);
1731
2489
        }
1732
2490
 
1733
2491
        /* Grant admin users everything */
1734
2492
        list ($ret, $groupId) = $module->getParameter('id.adminGroup');
1735
 
        if ($ret->isError()) {
 
2493
        if ($ret) {
1736
2494
            return $ret->wrap(__FILE__, __LINE__);
1737
2495
        }
1738
2496
 
1739
2497
        $ret = GalleryCoreApi::addGroupPermission($album->getId(), $groupId, 'core.all');
1740
 
        if ($ret->isError()) {
 
2498
        if ($ret) {
1741
2499
            return $ret->wrap(__FILE__, __LINE__);
1742
2500
        }
1743
2501
 
1744
2502
        $ret = $module->setParameter('id.rootAlbum', $album->getId());
1745
 
        if ($ret->isError()) {
 
2503
        if ($ret) {
1746
2504
            return $ret->wrap(__FILE__, __LINE__);
1747
2505
        }
1748
2506
 
1749
 
        return GalleryStatus::success();
 
2507
        return null;
1750
2508
    }
1751
2509
 
1752
2510
    /**
1762
2520
        /* Do we already have a root? */
1763
2521
        list ($ret, $compacterLockId) = $module->getParameter('id.accessListCompacterLock');
1764
2522
        if ($compacterLockId) {
1765
 
            return GalleryStatus::success();
 
2523
            return null;
1766
2524
        }
1767
2525
 
1768
 
        GalleryCoreApi::relativeRequireOnce('modules/core/classes/GalleryEntity.class');
 
2526
        GalleryCoreApi::requireOnce('modules/core/classes/GalleryEntity.class');
1769
2527
        $lock = new GalleryEntity();
1770
2528
        $lock->create();
1771
2529
        $ret = $lock->save(false);
1772
 
        if ($ret->isError()) {
 
2530
        if ($ret) {
1773
2531
            return $ret->wrap(__FILE__, __LINE__);
1774
2532
        }
1775
2533
 
1776
2534
        $ret = $module->setParameter('id.accessListCompacterLock', $lock->getId());
1777
 
        if ($ret->isError()) {
 
2535
        if ($ret) {
1778
2536
            return $ret->wrap(__FILE__, __LINE__);
1779
2537
        }
1780
2538
 
1781
 
        return GalleryStatus::success();
 
2539
        return null;
1782
2540
    }
1783
2541
 
1784
2542
    /**
1825
2583
        $regs[] = array('MaintenanceTask', 'ResetViewCountsTask', 'class', null);
1826
2584
        $regs[] = array('MaintenanceTask', 'SystemInfoTask', 'class', null);
1827
2585
        $regs[] = array('MaintenanceTask', 'SetOriginationTimestampTask', 'class', null);
 
2586
        $regs[] = array('MaintenanceTask', 'DeleteSessionsTask', 'class', null);
 
2587
        $regs[] = array('CaptchaAdminOption', 'CoreCaptchaAdminOption', 'class', null);
1828
2588
 
1829
2589
        /*
1830
2590
         * Unlike other modules, the core module doesn't get deactivated so its
1833
2593
         */
1834
2594
        /* Unregister all factory implementations */
1835
2595
        $ret = GalleryCoreApi::unregisterFactoryImplementationsByModuleId($module->getId());
1836
 
        if ($ret->isError()) {
 
2596
        if ($ret) {
1837
2597
            return $ret->wrap(__FILE__, __LINE__);
1838
2598
        }
1839
2599
 
1843
2603
                $entry[2] == 'class' ?
1844
2604
                  sprintf('modules/core/classes/%s.class', $entry[1]) :
1845
2605
                  sprintf('modules/core/%s.inc', $entry[1]),
1846
 
                'core', $entry[3], isset($entry[4]) ? $entry[4] : 4);
1847
 
            if ($ret->isError()) {
 
2606
                'core', $entry[3], isset($entry[4]) ? (string)$entry[4] : '4');
 
2607
            if ($ret) {
1848
2608
                return $ret->wrap(__FILE__, __LINE__);
1849
2609
            }
1850
2610
        }
1851
2611
 
1852
 
        return GalleryStatus::success();
 
2612
        return null;
1853
2613
    }
1854
2614
}
1855
2615
?>