From: Bharat M. <bh...@us...> - 2002-10-26 08:14:01
|
Update of /cvsroot/gallery/gallery2/modules/core/classes In directory usw-pr-cvs1:/tmp/cvs-serv6993/modules/core/classes Modified Files: Gallery.class GalleryEntity.class GalleryGroup.class GalleryItem.class GalleryModule.class GalleryPlatform.class GallerySession.class GalleryUserGroupMap.class Log Message: * Changed the way that module installs works. Moved the core install code out of setup.php & unit tests, and into the module.inc itself. GalleryModule now has an install() method where the module can allow the GalleryStore to do all of its configuration. This has several big benefits: - we don't have to duplicate initial params for the core in the setup.php and unit tests anymore. - we can upgrade the core by dropping in a new version - the core acts pretty much the same as any other module * Permissions now have an 'admin' flag. Any permission that allows editting of an item should have this flag turned on. This will allow us to quickly determine if we should display the [edit item] link * "All admins" is now "Site admins" * GalleryModule now has setModuleParameter/getModuleParameter convenience methods * core:SiteAdmin - AdminModules now has an 'install' option for new modules * removed dataVersion from GalleryEntity -- it's vestigal Index: Gallery.class =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/core/classes/Gallery.class,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- Gallery.class 22 Oct 2002 07:46:43 -0000 1.33 +++ Gallery.class 26 Oct 2002 08:13:26 -0000 1.34 @@ -204,8 +204,8 @@ * GalleryStorage instance. */ function reset() { - $this->_locks = array(); $this->_modules = array(); + $this->_locks = array(); $this->_storage = null; } Index: GalleryEntity.class =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/core/classes/GalleryEntity.class,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- GalleryEntity.class 16 Oct 2002 06:22:03 -0000 1.7 +++ GalleryEntity.class 26 Oct 2002 08:13:26 -0000 1.8 @@ -70,20 +70,6 @@ var $_creationTimestamp; /** - * Data version of this GalleryEntity - * - * @g2 <member> - * @g2 <member-name>dataVersion</member-name> - * @g2 <member-type>INTEGER</member-type> - * @g2 <required/> - * @g2 </member> - * - * @var float $_dataVersion - * @access private - */ - var $_dataVersion; - - /** * Date and time this item was last modified, in seconds since the epoch. * * @g2 <member> Index: GalleryGroup.class =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/core/classes/GalleryGroup.class,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- GalleryGroup.class 16 Oct 2002 06:47:48 -0000 1.15 +++ GalleryGroup.class 26 Oct 2002 08:13:26 -0000 1.16 @@ -34,11 +34,11 @@ define('GROUP_ALL_USERS', 2); /** - * The "all admins" group + * The "site admins" group * - * @constant GROUP_ALL_ADMINS + * @constant GROUP_SITE_ADMINS */ -define('GROUP_ALL_ADMINS', 3); +define('GROUP_SITE_ADMINS', 3); /* Load the parent class */ require_once(dirname(__FILE__) . '/GalleryEntity.class'); Index: GalleryItem.class =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/core/classes/GalleryItem.class,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- GalleryItem.class 22 Oct 2002 07:46:43 -0000 1.29 +++ GalleryItem.class 26 Oct 2002 08:13:27 -0000 1.30 @@ -419,8 +419,8 @@ $where .= ' OR [GalleryPermissionMap::userId] = ?)'; $data[] = $userId; $where .= ' AND'; - $where .= ' [GalleryPermissionMap::permission] IN (?, ?)))'; - $data = array_merge($data, array('core.view', 'core.all')); + $where .= ' [GalleryPermissionMap::permission] IN (?, ?, ?)))'; + $data = array_merge($data, array('core.view', 'core.viewAll', 'core.all')); list ($ret, $searchResults) = $gallery->search(array('select' => 'COUNT(DISTINCT([GalleryChildEntity::id]))', @@ -473,8 +473,8 @@ $where .= ' OR [GalleryPermissionMap::userId] = ?)'; $data[] = $userId; $where .= ' AND'; - $where .= ' [GalleryPermissionMap::permission] IN (?, ?)))'; - $data = array_merge($data, array('core.view', 'core.all')); + $where .= ' [GalleryPermissionMap::permission] IN (?, ?, ?)))'; + $data = array_merge($data, array('core.view', 'core.viewAll', 'core.all')); $orderBy = ' [GalleryItem::' . $this->getOrderBy() . ']'; if ($this->getOrderDirection() == ORDER_ASCENDING) { Index: GalleryModule.class =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/core/classes/GalleryModule.class,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- GalleryModule.class 22 Oct 2002 07:46:43 -0000 1.7 +++ GalleryModule.class 26 Oct 2002 08:13:27 -0000 1.8 @@ -100,6 +100,15 @@ } /** + * Perform any install/upgrade tasks at this point. + * + * @return object GalleryStatus a status code + */ + function install() { + return GalleryStatus::success(); + } + + /** * Activate this module * * @return object GalleryStatus a status code @@ -161,7 +170,7 @@ } /** - * Does this module require configuration? + * Does this module require configuration before it can be activated? * * @return array object GalleryStatus a status code * boolean @@ -169,18 +178,7 @@ function needsConfiguration() { global $gallery; - list ($ret, $version) = $gallery->getModuleParameter($this->getName(), - 'version'); - if ($ret->isError()) { - return $ret->wrap(__FILE__, __LINE__); - } - - /* If the versions don't match, we need to configure */ - if ($version != $this->getVersion()) { - return array(GalleryStatus::success(), true); - } else { - return array(GalleryStatus::success(), false); - } + return array(GalleryStatus::success(), false); } /** @@ -261,6 +259,34 @@ */ function getItemDetails($item, $returnUrlParams) { return array(GalleryStatus::success(), array()); + } + + /** + * @see Gallery::getModuleParameter() + */ + function getModuleParameter($parameterName) { + global $gallery; + list ($ret, $value) = + $gallery->getModuleParameter($this->getName(), $parameterName); + if ($ret->isError()) { + return array($ret->wrap(__FILE__, __LINE__), null); + } + + return array(GalleryStatus::success(), $value); + } + + /** + * @see Gallery::setModuleParameter() + */ + function setModuleParameter($parameterName, $parameterValue) { + global $gallery; + $ret = $gallery->setModuleParameter($this->getName(), + $parameterName, $parameterValue); + if ($ret->isError()) { + return $ret->wrap(__FILE__, __LINE__); + } + + return GalleryStatus::success(); } /* Getters and setters below */ Index: GalleryPlatform.class =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/core/classes/GalleryPlatform.class,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- GalleryPlatform.class 30 Sep 2002 08:42:12 -0000 1.13 +++ GalleryPlatform.class 26 Oct 2002 08:13:27 -0000 1.14 @@ -392,7 +392,6 @@ /* Convert string permission representation to octal */ $octalPerms = octdec($stringPerms); $gallery->debug(sprintf("mkdir(%s, %o)", $path, $octalPerms)); - printf("mkdir(%s, %o)<br>", $path, $octalPerms); $results = mkdir($path, $octalPerms); umask($umask); Index: GallerySession.class =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/core/classes/GallerySession.class,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- GallerySession.class 22 Oct 2002 07:46:43 -0000 1.1 +++ GallerySession.class 26 Oct 2002 08:13:27 -0000 1.2 @@ -169,6 +169,14 @@ $this->_sessionId = md5(microtime() . rand(1, 1000000000)); } + /* Precache a few keys that we know we'll need. */ + $ret = $this->_loadKeys(array('core.session.creationTime', + 'core.session.lifetime', + 'core.session.lastModified')); + if ($ret->isError()) { + return $ret->wrap(__FILE__, __LINE__); + } + /* Set our creation time, if necessary. */ list ($ret, $creationTime) = $this->get('core.session.creationTime'); if (empty($creationTime)) { @@ -259,7 +267,7 @@ print $ret->getAsHtml(); } - $ret = $this->_expireInactiveSessions(); + $ret = $this->_expireSessions(); if ($ret->isError()) { /* * We're getting called inside a shutdown handler -- can't @@ -300,12 +308,12 @@ /** * Get rid of any sessions that have not been accessed within our - * inactivity timeout. + * inactivity timeout or have exceeded the max lifetime. * * @return object GalleryStatus a status code. * @access private */ - function _expireInactiveSessions() { + function _expireSessions() { global $gallery; /* @@ -326,7 +334,7 @@ if ($sessionInactivityTimeout > 0) { - /* Find any session ids that exceed the inactivity timeout */ + /* Find any sessions that are expired */ list ($ret, $searchResults) = $gallery->search(array('select' => '[GallerySession::sessionId]', 'where' => ('([GallerySession::key] = ? ' . @@ -383,7 +391,7 @@ * string the value */ function get($key) { - $ret = $this->_loadKeys(array($key)); + $ret = $this->_loadKeys($key); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } @@ -400,7 +408,7 @@ */ function put($key, $value) { - $ret = $this->_loadKeys(array($key)); + $ret = $this->_loadKeys($key); if ($ret->isError()) { return $ret->wrap(__FILE__, __LINE__); } @@ -428,6 +436,11 @@ function _loadKeys($keys) { global $gallery; + /* Convert a single argument into an array if necessary */ + if (!is_array($keys)) { + $keys = array($keys); + } + /* * Remove any keys for which we already know the status, since those * are already assumed to be loaded. @@ -446,8 +459,7 @@ list ($ret, $searchResults) = $gallery->search(array('select' => '[GallerySession::key], [GallerySession::value]', 'where' => ('[GallerySession::sessionId] = ?' . - ' AND [GallerySession::key] IN (' . $markers . ')'), - 'limit' => array('count' => 1)), + ' AND [GallerySession::key] IN (' . $markers . ')')), $data); if ($ret->isError()) { return $ret->wrap(__FILE__, __LINE__); Index: GalleryUserGroupMap.class =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/core/classes/GalleryUserGroupMap.class,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- GalleryUserGroupMap.class 22 Oct 2002 07:46:43 -0000 1.7 +++ GalleryUserGroupMap.class 26 Oct 2002 08:13:27 -0000 1.8 @@ -224,7 +224,8 @@ * Is the given user id in the admin group? * * @param int the id of the user - * @return object GalleryStatus a status code + * @return array object GalleryStatus a status code + * bool true if yes */ function isUserInAdminGroup($userId) { global $gallery; @@ -234,14 +235,20 @@ return $ret->wrap(__FILE__, __LINE__); } - return GalleryUserGroupMap::isUserInGroup($userId, $adminGroupId); + list ($ret, $result) = GalleryUserGroupMap::isUserInGroup($userId, $adminGroupId); + if ($ret->isError()) { + return $ret->wrap(__FILE__, __LINE__); + } + + return array(GalleryStatus::success(), $result); } /** * Is the given user id in the given group? * * @param int the id of the user - * @return object GalleryStatus a status code + * @return array object GalleryStatus a status code + * bool true if yes */ function isUserInGroup($userId, $groupId) { global $gallery; @@ -257,7 +264,7 @@ } $result = $searchResults->nextResult(); - return array($ret, $result[0] == 1); + return array(GalleryStatus::success(), $result[0] == 1); } } |