コード例 #1
0
ファイル: utils.php プロジェクト: nyeholt/relapse
/**
 * Shortcut for NovemberApplication::getInstance()
 *
 * @return NovemberApplication
 */
function za()
{
    $instance = NovemberApplication::getInstance();
    if ($instance == null) {
        debug_print_backtrace();
    }
    return $instance;
}
コード例 #2
0
ファイル: update_task_owner.php プロジェクト: nyeholt/relapse
ini_set('display_errors', 'On');
ini_set('error_reporting', E_ALL | E_NOTICE);
ini_set('error_log', dirname(__FILE__) . '/error.log');
// This is where the common library of helpers is located for Zend Framework things.
// At the moment it's a global path just so it's available for all ZF apps
// $globalLib = 'd:/www/common-php-lib';
$generalIncludes = 'd:/www/includes';
set_include_path(get_include_path() . PATH_SEPARATOR . $generalIncludes . PATH_SEPARATOR . APP_DIR);
include_once APP_DIR . '/config.php';
include_once 'Zend/Loader.php';
function __autoload($class)
{
    Zend_Loader::loadClass($class);
}
include_once 'november/NovemberApplication.php';
$app = NovemberApplication::getInstance($config);
$app->init();
$dbService = za()->getService('DbService');
$projectService = za()->getService('ProjectService');
// Okay, need to first get the DB, select all the tasks, and change the assigned users
// to an array. Next, need to re-save the task to make sure the assigned users
// are correct in the usertaskassignment table.
$select = $dbService->select();
$select->from('task', array('id', 'userid'));
$result = $dbService->query($select, null);
$rows = new ArrayObject($result->fetchAll(Zend_Db::FETCH_ASSOC));
foreach ($rows as $row) {
    echo "Checking user " . $row['userid'] . "\n";
    if (mb_strpos($row['userid'], '{') === false) {
        $task = $projectService->getTask($row['id']);
        echo "Changing " . $task->title . "\n";
コード例 #3
0
 /**
  * Dispatch to a controller/action
  *
  * Overridden so that the created controller is injected
  * with services. 
  * 
  * @param Zend_Controller_Request_Abstract $request
  * @param Zend_Controller_Response_Abstract $response
  * @return boolean
  * @throws Zend_Controller_Dispatcher_Exception
  */
 public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response)
 {
     $this->setResponse($response);
     /**
      * Get controller class
      */
     if (!$this->isDispatchable($request)) {
         $controller = $request->getControllerName();
         if (!$this->getParam('useDefaultControllerAlways') && !empty($controller)) {
             require_once 'Zend/Controller/Dispatcher/Exception.php';
             throw new Zend_Controller_Dispatcher_Exception('Invalid controller specified (' . $request->getControllerName() . ')');
         }
         $className = $this->getDefaultControllerClass($request);
     } else {
         $className = $this->getControllerClass($request);
         if (!$className) {
             $className = $this->getDefaultControllerClass($request);
         }
     }
     /**
      * Load the controller class file
      */
     $className = $this->loadClass($className);
     $__start = getmicrotime();
     /**
      * Instantiate controller with request, response, and invocation 
      * arguments; throw exception if it's not an action controller
      */
     $controller = new $className($request, $this->getResponse(), $this->getParams());
     if (!$controller instanceof Zend_Controller_Action_Interface && !$controller instanceof Zend_Controller_Action) {
         require_once 'Zend/Controller/Dispatcher/Exception.php';
         throw new Zend_Controller_Dispatcher_Exception("Controller '{$className}' is not an instance of Zend_Controller_Action");
     }
     NovemberApplication::getInstance()->inject($controller);
     $controller->view = Zend_Registry::get(NovemberApplication::$ZEND_VIEW);
     /**
      * Retrieve the action name
      */
     $action = $this->getActionMethod($request);
     /**
      * Dispatch the method call
      */
     $request->setDispatched(true);
     // by default, buffer output
     $disableOb = $this->getParam('disableOutputBuffering');
     $obLevel = ob_get_level();
     if (empty($disableOb)) {
         ob_start();
     }
     try {
         $controller->dispatch($action);
     } catch (Exception $e) {
         // Clean output buffer on error
         $curObLevel = ob_get_level();
         if ($curObLevel > $obLevel) {
             do {
                 ob_get_clean();
                 $curObLevel = ob_get_level();
             } while ($curObLevel > $obLevel);
         }
         throw $e;
     }
     if (empty($disableOb)) {
         $content = ob_get_clean();
         $response->appendBody($content);
     }
     // Destroy the page controller instance and reflection objects
     $controller = null;
     za()->recordStat('injectingdispatcher::dispatched-' . get_class($controller) . ':' . $action, getmicrotime() - $__start);
 }
コード例 #4
0
 /**
  * Called before an action is dispatched by Zend_Controller_Dispatcher.
  *
  * This callback allows for proxy or filter behavior.  The
  * $action must be returned for the Zend_Controller_Dispatcher_Token to be dispatched.
  * To abort the dispatch, return FALSE.
  *
  * @param  Zend_Controller_Request_Http $action
  * @return Zend_Controller_Request_Http
  */
 public function preDispatch($action)
 {
     /*@var $action Zend_Controller_Request_Http */
     $controllerName = strtolower($action->getControllerName());
     $actionName = strtolower($action->getActionName());
     $moduleName = strtolower($action->getModuleName());
     // Check for authorization.
     $app = NovemberApplication::getInstance();
     $currentUser = $app->getUser();
     if ($currentUser->getRole() == User::ROLE_LOCKED) {
         $action->setControllerName(ifset($this->config, 'login_controller', 'user'));
         $action->setActionName(ifset($this->config, 'login_action', 'login'));
         return $action;
     }
     // Get the restrictions for the current request (if any)
     $conf = ifset($this->config, $moduleName);
     $roles = '';
     if (is_string($conf)) {
         $roles = $conf;
     } else {
         if (is_array($conf)) {
             // check for a default
             $roles = ifset($conf, 'default_roles', '');
             // If there's something in the controllername entry...
             $controllerConf = ifset($conf, $controllerName, $roles);
             if (is_array($controllerConf)) {
                 $roles = ifset($controllerConf, $actionName, $roles);
             } else {
                 $roles = $controllerConf;
             }
         }
     }
     // Are there required roles to authenticate?
     $loginRequired = false;
     za()->log(__CLASS__ . ':' . __LINE__ . " - Authorizing " . $currentUser->getUsername() . " for roles {$roles}");
     if ($roles != '') {
         $loginRequired = true;
         $roles = explode(',', $roles);
         // If the user has any of the roles, let them in
         foreach ($roles as $role) {
             if ($currentUser->hasRole($role)) {
                 return $action;
             }
         }
     }
     // If we've got this far, then we should ask the DB if the current user has
     // access to the current module and controller
     // We're expecting user_access =>
     // user_role
     // OR array (controller => user_role)
     $userAccess = ifset($conf, 'user_access');
     if ($userAccess != null) {
         $loginRequired = true;
         // if it's a string, just get the access for the module
         $accessService = za()->getService('AccessService');
         // See if they have access to this module
         $access = $accessService->getAccessList($currentUser->getUsername(), $moduleName);
         if (count($access)) {
             // okay, they have access, so we're all cool
             return $action;
         }
     }
     if ($loginRequired) {
         $url = build_url($controllerName, $actionName, $action->getUserParams(), false, $moduleName);
         $_SESSION[NovemberController::RETURN_URL] = $url;
         // $action->setModuleName(ifset($this->config, 'login_module', 'default'));
         $action->setControllerName($this->config['login_controller']);
         $action->setActionName($this->config['login_action']);
     }
     return $action;
 }