function perform() { if (!count($this->states)) return; if($this->initial_state) $next_state = $this->initial_state; else { reset($this->states); $next_state = key($this->states); } while($next_state != false) { $state = $next_state; $result = $this->_performStateCommand($state); if (isset($this->states[$state]['transitions'][$result])) $next_state = $this->states[$state]['transitions'][$result]; elseif(isset($this->states[$state]['transitions'][STATE_MACHINE_BY_DEFAULT])) $next_state = $this->states[$state]['transitions'][STATE_MACHINE_BY_DEFAULT]; else return $result; if(catch_error('LimbException', $e)) return throw_error($e); } }
function testResolveDataMapperFileFailed() { die_on_error(false); $this->resolver->resolve('no_such_mapper'); $this->assertTrue(catch_error('LimbException', $e)); die_on_error(); }
function testResolveDbTableFileFailed() { die_on_error(false); $this->resolver->resolve('no_such_db_table'); $this->assertTrue(catch_error('LimbException', $e)); die_on_error(); }
function testResolveObjectFileFailed() { die_on_error(false); $this->resolver->resolve('no_such_object'); $this->assertTrue(catch_error('LimbException', $e)); die_on_error(); }
function resize($max_size) { $image_library =& $this->_getImageLibrary(); $media_manager =& $this->_getMediaManager(); $media_file_id = $this->getMediaFileId(); $input_file = $media_manager->getMediaFilePath($media_file_id); $output_file = $this->_generateTempFile(); $input_file_type = $image_library->getImageType($this->getMimeType()); $output_file_type = $image_library->fallBackToAnySupportedType($input_file_type); $image_library->setInputFile($input_file); $image_library->setInputType($input_file_type); $image_library->setOutputFile($output_file); $image_library->setOutputType($output_file_type); $image_library->resize(array('max_dimension' => $max_size)); //ugly!!! $image_library->commit(); if (catch_error('LimbException', $e)) { if (file_exists($output_file)) { $this->_unlinkTempFile($output_file); } return throw_error($e); } $this->_updateDimensionsUsingFile($output_file); $media_file_id = $media_manager->store($output_file); $this->setMediaFileId($media_file_id); $this->_unlinkTempFile($output_file); }
function _applyAccessPolicy($object, $action) { $access_policy = new AccessPolicy(); $access_policy->applyAccessTemplates($object, $action); if (catch_error('LimbException', $e)) { } MessageBox::writeNotice("Access template of " . get_class($object) . " for action '{$action}' not defined!!!"); }
function _updateObjectOperation() { $this->object->set('files_data', $_FILES[$this->name]); $this->object->updateVariations(); if (catch_error('SQLException', $e)) { return throw_error($e); } elseif (catch_error('LimbException', $e)) { MessageBox::writeNotice('Some variations were not resized'); } elseif (catch_error('LimbException', $e)) { return throw_error($e); } }
function testResolveStringsFileFailed() { die_on_error(false); $this->resolver->resolve('no_such_strings_file', array('fr')); $this->assertTrue(catch_error('LimbException', $e)); $this->assertEqual($e->getAdditionalParams(), array( 'file_path' => 'i18n/no_such_strings_file_fr.ini', )); die_on_error(); }
function testGetRequestedService404IfNoIni() { $toolkit =& Limb :: toolkit(); $request = $toolkit->getRequest(); $resolver = new IniBasedServiceRequestResolver(); die_on_error(false); $service = $resolver->resolve($request); die_on_error(); $this->assertTrue(catch_error('LimbException', $e)); }
function testFailedInsertNoOId() { $object = new ServiceLocation(); $mapper = new ServiceLocationMapper(); die_on_error(false); $mapper->insert($object); die_on_error(); $this->assertTrue(catch_error('LimbException', $e)); $this->assertEqual($e->getMessage(), 'oid is not set'); }
function testPerformFailedNoView() { $command = new DisplayViewCommand(); $this->toolkit->expectOnce('getView'); $this->toolkit->setReturnValue('getView', null); die_on_error(false); $command->perform(); $this->assertTrue(catch_error('LimbException', $e)); die_on_error(); }
function testFailedInsertNoObjectId() { $object = new NodeConnection(); $object->set('oid', 10); $mapper = new NodeConnectionMapper(); die_on_error(false); $mapper->insert($object); die_on_error(); $this->assertTrue(catch_error('LimbException', $e)); $this->assertEqual($e->getMessage(), 'node id is not set'); }
function _validPerform(&$request, &$response) { $params = array(); $params['identifier'] = $this->dataspace->get('identifier'); $params['parent_path'] = $this->dataspace->get('parent_path'); $params['class'] = $this->dataspace->get('class_name'); $params['title'] = $this->dataspace->get('title'); $toolkit =& Limb::toolkit(); $object =& $toolkit->createSiteObject($params['Class']); $datasource =& $toolkit->getDatasource('SingleObjectDatasource'); $datasource->setPath($params['parent_path']); $is_root = false; if (!($parent_data = $datasource->fetch())) { if ($params['parent_path'] == '/') { $is_root = true; } else { MessageBox::writeNotice('parent wasn\'t retrieved by path ' . $params['parent_path']); $request->setStatus(Request::STATUS_FAILURE); return; } } if (!$is_root) { $params['parent_node_id'] = $parent_data['node_id']; } else { $params['parent_node_id'] = 0; } $object->merge($params); $object->create($is_root); if (catch_error($e, 'LimbException')) { MessageBox::writeNotice('object wasn\'t registered!'); $request->setStatus(Request::STATUS_FAILURE); return; } elseif (catch_error($e, 'LimbException')) { return throw_error($e); } if (!$is_root) { $parent_object =& $toolkit->createSiteObject($parent_data['ClassName']); $parent_object->merge($parent_data); $controller =& $parent_object->getController(); $action = $controller->determineAction(); $access_policy = new AccessPolicy(); $access_policy->saveNewObjectAccess($object, $parent_object, $action); } $request->setStatus(Request::STATUS_FORM_SUBMITTED); if ($request->hasAttribute('popup')) { $response->write(closePopupResponse($request)); } }
function load(&$authorizor) { $toolkit =& Limb::toolkit(); $ini =& $toolkit->getIni('acl.ini'); if (catch_error('LimbException', $e)) { return; } if (!$ini->hasOption('policy')) { return; } $policy_lines = $ini->getOption('policy'); foreach ($policy_lines as $line) { $policy = preg_split("/[\\s,]+/", $line); $authorizor->attachPolicy($policy[0], $policy[1], (int) $policy[2]); } }
function insert(&$object) { if (!$class_id = $this->getClassId($object)) return throw_error(new LimbException('class id is empty')); $toolkit =& Limb :: toolkit(); $db_table = $toolkit->createDBTable('SysObject'); $raw_data = array(); $raw_data['oid'] = $object->get('oid'); $raw_data['class_id'] = $class_id; $db_table->insert($raw_data); if(catch_error('LimbException', $e)) return throw_error($e); $object->set('class_id', $class_id); }
function getIni($file_name, $use_cache = null, $resolver_name = 'ini') { if (isset($GLOBALS['testing_ini'][$file_name])) { $resolved_file = VAR_DIR . '/' . $file_name; $use_cache = false; } else { $resolver =& Handle :: resolve(getFileResolver($resolver_name)); $resolved_file = $resolver->resolve($file_name); if (catch_error('LimbException', $e)) { throw_error($e); return; } } return new Ini($resolved_file, $use_cache); }
function resolve($file_path, $params = array()) { $toolkit =& Limb :: toolkit(); $ini =& $toolkit->getINI('common.ini'); $tmpl_path = $ini->getOption('templates_path', 'Templates'); $shared_tmpl_path = $ini->getOption('shared_templates_path', 'Templates'); $locale = $this->_getLocalePrefix(); if(file_exists($tmpl_path . $locale . $file_path)) return $tmpl_path . $locale . $file_path; if(file_exists($tmpl_path . $file_path)) return $tmpl_path . $file_path; die_on_error(false); $res = $this->_resolver->resolve('design/' . $locale . $file_path, $params); if(catch_error('LimbException', $e)) $res = $this->_resolver->resolve('design/' . $file_path, $params); if(catch_error('LimbException', $e)) { if(file_exists($shared_tmpl_path . $locale . $file_path)) return $shared_tmpl_path . $locale . $file_path; if(file_exists($shared_tmpl_path . $file_path)) return $shared_tmpl_path . $file_path; throw_error($e); } die_on_error(); return $res; }
function update_70x_to_706($type = '') { global $sql, $ns, $pref, $e107info, $admin_log, $emessage; $just_check = $type == 'do' ? FALSE : TRUE; if (!$sql->db_Field("plugin", 5)) { if ($just_check) { return update_needed(); } $sql->db_Select_gen("ALTER TABLE `" . MPREFIX . "plugin` ADD `plugin_addons` TEXT NOT NULL ;"); catch_error($sql); } //rename plugin_rss field if ($sql->db_Field("plugin", 5) == "plugin_rss") { if ($just_check) { return update_needed(); } $sql->db_Select_gen("ALTER TABLE `" . MPREFIX . "plugin` CHANGE `plugin_rss` `plugin_addons` TEXT NOT NULL;"); catch_error($sql); } if ($sql->db_Field("dblog", 5) == "dblog_query") { if ($just_check) { return update_needed(); } $sql->db_Select_gen("ALTER TABLE `" . MPREFIX . "dblog` CHANGE `dblog_query` `dblog_title` VARCHAR( 255 ) NOT NULL DEFAULT '';"); catch_error($sql); $sql->db_Select_gen("ALTER TABLE `" . MPREFIX . "dblog` CHANGE `dblog_remarks` `dblog_remarks` TEXT NOT NULL;"); catch_error($sql); } if (!$sql->db_Field("plugin", "plugin_path", "UNIQUE")) { if ($just_check) { return update_needed(); } if (!$sql->db_Select_gen("ALTER TABLE `" . MPREFIX . "plugin` ADD UNIQUE (`plugin_path`);")) { $mesg = LAN_UPDATE_12 . " : <a href='" . e_ADMIN . "db.php?plugin'>" . ADLAN_145 . "</a>."; //$ns -> tablerender(LAN_ERROR,$mes); $emessage->add($mesg, E_MESSAGE_ERROR); catch_error($sql); } } if (!$sql->db_Field("online", 6)) { if ($just_check) { return update_needed(); } $sql->db_Select_gen("ALTER TABLE " . MPREFIX . "online ADD online_active INT(10) UNSIGNED NOT NULL DEFAULT '0'"); catch_error($sql); } if ($sql->db_Query("SHOW INDEX FROM " . MPREFIX . "tmp")) { $row = $sql->db_Fetch(); if (!in_array('tmp_ip', $row)) { if ($just_check) { return update_needed(); } $sql->db_Select_gen("ALTER TABLE `" . MPREFIX . "tmp` ADD INDEX `tmp_ip` (`tmp_ip`);"); $sql->db_Select_gen("ALTER TABLE `" . MPREFIX . "upload` ADD INDEX `upload_active` (`upload_active`);"); $sql->db_Select_gen("ALTER TABLE `" . MPREFIX . "generic` ADD INDEX `gen_type` (`gen_type`);"); } } if (!$just_check) { // update new fields require_once e_HANDLER . "plugin_class.php"; $ep = new e107plugin(); $ep->update_plugins_table('update'); $ep->save_addon_prefs('update'); } if (!isset($pref['displayname_maxlength'])) { if ($just_check) { return update_needed(); } $pref['displayname_maxlength'] = 15; save_prefs(); } // If we get to here, in checking mode no updates are required. In update mode, all done. if ($just_check) { return TRUE; } e107::getLog()->add('UPDATE_02', LAN_UPDATE_14 . $e107info['e107_version'], E_LOG_INFORMATIVE, ''); // Log result of actual update return $just_check; // TRUE if no updates needed, FALSE if updates needed and completed }
function run() { $this->_registerFileResolvers(); $this->_registerToolkit(); $this->_loadPackages(); $toolkit =& Limb :: toolkit(); $request =& $toolkit->getRequest(); $response =& $toolkit->getResponse(); $filter_chain = new FilterChain($request, $response); $this->_registerFilters($filter_chain); $filter_chain->process(); if(catch_error('LimbException', $e)) { Debug :: writeException($e); } elseif(catch_error('LimbException', $e)) { echo 'Unexpected PHP exception in ' . $e->getFile() . ' in line ' . $e->getLine(); echo '<br>'; echo '<pre>'; echo $e->getTraceAsString(); echo '</pre>'; echo 'Report this error to the LIMB developers, please.'; exit(); } }
function testCantDeleteNoNodeId() { $mapper = new TreeNodeDataMapper(); $object = new Object(); die_on_error(false); $mapper->delete($object); die_on_error(); $this->assertTrue(catch_error('LimbException', $e)); $this->assertEqual($e->getMessage(), 'node id not set'); }
function testStateWithBrokenTransitions() { $factory = new MockCommandsFactory($this); $state_machine = new StateMachineCommand($factory); $state_machine->registerState('Initial', array('some_result' => 'NoSuchState')); $state_machine->registerState('NextState'); $state_machine->registerState('ExtraState'); $factory->expectOnce('performInitial'); $factory->setReturnValueAt(0, 'performInitial', 'some_result'); $factory->expectNever('performNextState'); $factory->expectNever('performExtraState'); die_on_error(false); $state_machine->perform(); $this->assertTrue(catch_error('LimbException', $e)); die_on_error(); }
$theme->redirect($link); } } catch (exceptionlist $e) { $link = catch_error($e, 'users.php?action=changeoptionsform&', $lang->translate('Options are not saved or saved partionelly'), $errorrep); $theme->redirect($link); } break; case 'viewuserlist': $theme->themefile('viewuserlist.html', true); $database->close(); break; case 'viewuser': $theme->themefile('viewuserprofile.html', true); $database->close(); break; case 'activate': try { if (empty($_GET['id'])) { throw new exceptionlist($lang->translate('ID must be set')); } $user->activate($_GET['id']); $link = 'index.php?note=' . $lang->translate('Your account is activated, you can login now'); $theme->redirect($link); } catch (exceptionlist $e) { $link = catch_error($e, 'index.php&', $lang->translate('Your account is not activated'), $errorrep); $theme->redirect($link); } default: $theme->redirect('index.php'); } // switch ($action)
try { $theme->themefile('editcomment.html', true); $database->close(); } catch (exceptionlist $e) { $link = catch_error($e, 'index.php?', $lang->translate('You can\'t open this page'), $errorrep); $database->close(); $theme->redirect($link); } break; case 'viewfeed': try { $meta['title'] = $config->getConfigByNameType('general/sitename', TYPE_STRING); $meta['description'] = $config->getConfigByNameType('general/description', TYPE_STRING); $meta['link'] = $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"]; $meta['link'] = ereg_replace('news.php', '', $meta['link']); if (!empty($_GET[GET_CATEGORY])) { $category = $_GET[GET_CATEGORY]; } else { $category = NULL; } echo $news->viewFeed($meta, $category, 'RSS2'); } catch (exceptionlist $e) { $link = catch_error($e, 'index.php?', $lang->translate('error running feed'), $errorrep); $database->close(); $theme->redirect($link); } break; default: $database->close(); $theme->redirect('index.php'); }
function _loadCache() { $this->reset(); $cache_dir = $this->cache_dir; Fs :: mkdir($cache_dir); if(catch_error('IOException', $e)) { Debug :: writeWarning('could not create cache directory for ini', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('cache_dir' => $cache_dir)); $this->_parse(); return; } if($override_file = $this->getOverrideFile()) $this->cache_file = $this->cache_dir . md5($override_file) . '.php'; else $this->cache_file = $this->cache_dir . md5($this->file_path) . '.php'; if ($this->_isCacheValid()) { $charset = null; $group_values = array(); include($this->cache_file); $this->charset = $charset; $this->group_values = $group_values; unset($group_values); } else { $this->_parse(); $this->_saveCache(); } }
function testResolveTemplateFileFailed() { die_on_error(false); $this->resolver->resolve('no_such_template.html'); $this->assertTrue(catch_error('LimbException', $e)); die_on_error(); }
include 'kernel/functions.php'; loadall(); if (!empty($_GET['action'])) { $action = $_GET['action']; } else { $theme->redirect('index.php'); } try { $errorrep = $config->getConfigByNameType('general/errorreporting', TYPE_INT); } catch (exceptionlist $e) { // this is a big errror so $errorep = true $link = catch_error($e, 'index.php?', $lang->translate('Your action has no effect'), true); $database->close(); $theme->redirect($link); } switch ($action) { case 'vote': try { $return = $poll->vote($_POST, $user->getconfig('name')); $database->close(); $theme->redirect('index.php?note=' . $lang->translate('You have voted')); break; } catch (exceptionlist $e) { $theme->redirect(catch_error($e, 'index.php?', $lang->translate('Your vote is not saved'), $errorrep)); } case 'allpolls': $theme->themefile('viewpolls.html'); break; default: $theme->redirect('index.php'); }
<?php //conn.php define("SQL_HOST", "localhost"); define("SQL_USER", "root"); define("SQL_PASS", ""); define("SQL_DB", "cms_site"); $conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS); mysql_select_db(SQL_DB, $conn) or catch_error(); function catch_error() { error_log("Error: Could not select the database: " . mysql_error() . "\n", 3, "debug.log"); die("Couldn't select the database: " . mysql_error()); }
function testSetupTargetsFailedNoSuchRuntimeTarget() { $component = new LimbDAOComponentSetupTargetsTestVersion($this); $component->parent = $this->parent; $this->parent->expectArgumentsAt(0, 'findChild', array('target1')); $this->parent->setReturnValueAt(0, 'findChild', null); $component->expectOnce('getDataset'); $dataset = new PagedArrayDataset(array('some_data')); $component->setReturnReference('getDataset', $dataset); $component->setTargets('target1, target2'); die_on_error(false); $component->process(); die_on_error(); $this->assertTrue(catch_error('LimbException', $e)); $component->tally(); }
function testDeleteNew() { $obj = new UOWTestObject(); die_on_error(false); $this->uow->delete($obj); die_on_error(); $this->assertTrue(catch_error('LimbException', $e)); $this->mapper->expectNever('delete'); $this->uow->commit(); }