Ejemplo n.º 1
0
    /**
     * Synchronize the code base
     *
     * This method is invoked whenever someone clicks on the "Sync" button. It
     * looks at the actions, looks at the existing files and either generate
     * the action if the action file doesn't exist or updates it whenever
     * it has to be updated (New required parameters, etc).
     *
     * @return void
     */
    public function sync()
    {
        $actions = $this->config->getAll('action');

        foreach ($actions as $key => $a) {
            $description = isset($a['description']) ? $a['description'] : false;
            $route = isset($a['route']) ? $a['route'] : false;

            if (empty($a)) {
                continue;
            }

            $params = array();

            if (isset($a['parameters']['parameter'])) {
                $params = $a['parameters']['parameter'];
            }

            if (count($params) && !isset($params[0])) {
                $params = array($params);
            }

            $p = array();
            if (!empty($params)) {
                foreach ($params as $param) {
                    if ($param['required'] == '1') {
                        $p[] = $param['name'];
                    }
                }
            }

            $name = ucfirst(strtolower($a['name']));
            $dir  = ROOT_PATH . DIRECTORY_SEPARATOR . 'custom' . DIRECTORY_SEPARATOR . 'Action';

            $file = $dir . DIRECTORY_SEPARATOR . $name . '.php';

            if (!file_exists($file)) {
                $content = $this->generateAction($name, $p, $description, $route);
            } else {
                $content = $this->updateAction($file, $name, $p);
            }

            if ($content !== false && $content !== null && strlen($content) > 8) {
                // Do atomic move
                $tempName = $name . sha1(mt_rand(1, 100000000) . microtime(true)) . '.php';
                file_put_contents($dir . DIRECTORY_SEPARATOR . $tempName, $content);
                rename($dir . DIRECTORY_SEPARATOR . $tempName, $file);
                chmod($file, 0777);
            }
        }

        $this->refreshAPCCache();
    }
Ejemplo n.º 2
0
 private function upgradeConfig($file)
 {
     file_put_contents($file, '<frapi-config><mimetypes/></frapi-config>');
     $config = new Lupin_Config_Xml('mimetypes');
     $mimetypes = array('application/xml' => 'xml', 'text/xml' => 'xml', 'application/json' => 'json', 'text/json' => 'json', 'text/html' => 'html', 'text/plain' => 'json', 'text/javascript' => 'js', 'text/php-printr' => 'printr');
     foreach ($mimetypes as $mimetype => $format) {
         $data = array('mimetype' => $mimetype, 'output_format' => $format, 'description' => '');
         $config->add('mimetype', $data);
     }
     return $config;
 }
Ejemplo n.º 3
0
 /**
  * Get all users
  *
  * Get all the users.
  *
  * @return mixed Either boolean false or an array of all users.
  */
 public function getAll()
 {
     $users = $this->config->getAll('user');
     return $users;
 }