From: Bharat M. <bh...@us...> - 2002-10-26 08:14:02
|
Update of /cvsroot/gallery/gallery2/modules/netpbm In directory usw-pr-cvs1:/tmp/cvs-serv6993/modules/netpbm Modified Files: AdminNetPbm.inc module.inc 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: AdminNetPbm.inc =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/netpbm/AdminNetPbm.inc,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- AdminNetPbm.inc 22 Oct 2002 07:46:45 -0000 1.7 +++ AdminNetPbm.inc 26 Oct 2002 08:13:29 -0000 1.8 @@ -74,25 +74,6 @@ return array($ret->wrap(__FILE__, __LINE__), null); } - list ($ret, $needsConfiguration) = $module->needsConfiguration(); - if ($ret->isError()) { - return array($ret->wrap(__FILE__, __LINE__), null); - } - - if ($needsConfiguration) { - /* - * If we get this far successfully, assume that the user has made - * at least a token effort to configure the module correctly. The - * test code in AdminNetPbmView should indicate whether or not they - * got it right. So, update our version in the map accordingly. - */ - $ret = $gallery->setModuleParameter($module->getName(), - 'version', $module->getVersion()); - if ($ret->isError()) { - return array($ret->wrap(__FILE__, __LINE__), null); - } - } - /* Figure out where to redirect upon success */ $redirectParams['view'] = 'core:SiteAdmin'; $redirectParams['subView'] = 'netpbm:AdminNetPbm'; Index: module.inc =================================================================== RCS file: /cvsroot/gallery/gallery2/modules/netpbm/module.inc,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- module.inc 7 Oct 2002 21:41:26 -0000 1.5 +++ module.inc 26 Oct 2002 08:13:29 -0000 1.6 @@ -53,11 +53,69 @@ } /** - * @see GalleryModule::getSiteAdminViews + * @see GalleryModule::install */ - function getSiteAdminViews() { + function install() { + list ($ret, $version) = $this->getModuleParameter('version'); + if ($ret->isError()) { + return $ret->wrap(__FILE__, __LINE__); + } + + if ($version != $this->getVersion()) { + if (empty($version)) { + /* + * This is an initial install. Make sure that we have some + * reasonable defaults. + */ + foreach (array('path' => '', + 'jpegQuality' => '75', + 'pnmtojpeg' => 'pnmtojpeg') + as $key => $value) { + + $ret = $this->setModuleParameter($key, $value); + if ($ret->isError()) { + return $ret->wrap(__FILE__, __LINE__); + } + } + } + + $ret = $this->setModuleParameter('version', $this->getVersion()); + if ($ret->isError()) { + return $ret->wrap(__FILE__, __LINE__); + } + } + + return GalleryStatus::success(); + } + + /** + * @see GalleryModule::needsConfiguration + */ + function needsConfiguration() { global $gallery; + /* + * This module requires all fields to be filled out before it can be + * activated. + */ + foreach (array('path', 'jpegQuality', 'pnmtojpeg') as $key) { + list ($ret, $value) = $this->getModuleParameter($key); + if ($ret->isError()) { + return $ret->wrap(__FILE__, __LINE__); + } + + if (empty($value)) { + return array(GalleryStatus::success(), true); + } + } + + return array(GalleryStatus::success(), false); + } + + /** + * @see GalleryModule::getSiteAdminViews + */ + function getSiteAdminViews() { return array(GalleryStatus::success(), array(array('name' => $this->translate('NetPBM'), 'view' => 'netpbm:AdminNetPbm'))); @@ -67,8 +125,6 @@ * @see GalleryModule::getConfigurationView */ function getConfigurationView() { - global $gallery; - return array(GalleryStatus::success(), 'netpbm:AdminNetPbm'); } } |