Exemplo n.º 1
0
 public function up_1()
 {
     if (!ADMIN_PLUGIN_RUNNING_ON_APPLICATION_SCOPE) {
         self::setTokenKey();
     }
     $this->createTable('users', '
       id,
       login string(40) not null idx,
       email string(50) not null idx,
       password string(40) not null,
       password_salt string(16) not null,
       last_login_at,
       is_enabled bool default 1
     ');
     $this->createTable('roles', '
       id,
       name,
       description,
       is_enabled bool default 1,
       parent_id,
       lft integer(8) index,
       rgt integer(8) index,
     ');
     $this->createTable('roles_users', 'id, role_id, user_id', array('timestamp' => false));
     $this->createTable('permissions_roles', 'id, permission_id, role_id', array('timestamp' => false));
     $this->createTable('extensions', 'id, name, is_core, is_enabled');
     $this->createTable('permissions', 'id, name, extension_id');
     if (AK_ENVIRONMENT != 'testing' && empty($this->root_details)) {
         $this->root_details = array('login' => AkConsole::promptUserVar('Master account login.', array('default' => 'admin')), 'email' => AkConsole::promptUserVar('Master account email.', array('default' => '*****@*****.**')), 'password' => AkConsole::promptUserVar('Root password.', array('default' => 'admin')));
     }
     $this->addDefaults();
 }
Exemplo n.º 2
0
 function hasCollisions()
 {
     $this->collisions = array();
     foreach (array_merge(array_values($this->files), array_values($this->user_actions)) as $file_name) {
         $user_answer = 5;
         if ($user_answer != 3 && file_exists($file_name)) {
             $message = Ak::t('%file_name file already exists', array('%file_name' => $file_name));
             $user_answer = AkConsole::promptUserVar($message . "\n" . "Would you like to:\n" . " 1) overwrite file\n" . " 2) keep existing file\n" . " 3) overwrite all\n" . " 4) keep all\n" . " 5) abort\n", array('default' => 5));
             if ($user_answer == 2 || $user_answer == 4) {
                 $this->_skip_files[] = $file_name;
             } elseif ($user_answer == 5) {
                 $this->collisions[] = $message;
             }
         }
     }
     return count($this->collisions) > 0;
 }
Exemplo n.º 3
0
 /**
  * Promts for a variable on console scripts
  */
 static function promptUserVar($message, $options = array())
 {
     $f = fopen("php://stdin", "r");
     $default_options = array('default' => null, 'optional' => false);
     $options = is_string($options) ? array('default' => $options) : $options;
     $options = array_merge($default_options, $options);
     echo "\n" . $message . (empty($options['default']) ? '' : ' [' . $options['default'] . ']') . ': ';
     $user_input = fgets($f, 25600);
     $value = trim($user_input, "\n\r\t ");
     $value = empty($value) ? $options['default'] : $value;
     if (empty($value) && empty($options['optional'])) {
         echo "\n\nThis setting is not optional.";
         fclose($f);
         return AkConsole::promptUserVar($message, $options);
     }
     fclose($f);
     return empty($value) ? $options['default'] : $value;
 }
Exemplo n.º 4
0
 public function install()
 {
     $core_dir = AK_CORE_DIR;
     $src_path = $this->getSrcPath() . '/akelos';
     $bin_path = $this->getBinaryPath();
     if (is_dir($src_path)) {
         if (AkConsole::promptUserVar("The directory {$src_path} is not empty. Do you want to override its contents? (y/n)", 'n') != 'y') {
             die("Aborted.\n");
         }
     }
     $this->ensureCanWriteOnDirectory($src_path);
     $this->ensureCanWriteOnDirectory($bin_path . '/akelos');
     $this->log("Copying souce files from {$core_dir} to {$src_path}.");
     $this->run("cp -R {$core_dir}/ {$src_path}/");
     $this->log("Linking binaries");
     $this->run(array('rm ' . $bin_path . '/akelos', "ln -s {$src_path}/akelos {$bin_path}/akelos"));
     $this->run(array('rm ' . $bin_path . '/makelos', "ln -s {$src_path}/makelos {$bin_path}/makelos"));
     $this->log("Done.");
 }
Exemplo n.º 5
0
    public function relativizeStylesheetPaths()
    {
        $url_suffix = AkConsole::promptUserVar('The admin plugin comes with some fancy CSS background images.

Your application might be accessible at /myapp, 
and your images folder might be at /myapp/public

Insert the relative path where your images folder is
so you don\'t need to manually edit the CSS files', array('default' => '/'));
        $url_suffix = trim(preg_replace('/\\/?images\\/admin\\/?$/', '', $url_suffix), '/');
        if (!empty($url_suffix)) {
            $stylesheets = array('admin/admin', 'admin/menu');
            foreach ($stylesheets as $stylesheet) {
                $filename = AK_PUBLIC_DIR . DS . 'stylesheets' . DS . $stylesheet . '.css';
                $relativized_css = preg_replace("/url\\((\\'|\")?\\/images/", "url(\$1/{$url_suffix}/images", @AkFileSystem::file_get_contents($filename));
                !empty($relativized_css) && @AkFileSystem::file_put_contents($filename, $relativized_css);
            }
        }
    }
Exemplo n.º 6
0
 protected function _checkForModified(&$directory_structure, $base_path = null, $src_path = null)
 {
     foreach ($directory_structure as $k => $node) {
         if (!empty($this->skip_all)) {
             return;
         }
         if (is_array($node)) {
             foreach ($node as $dir => $items) {
                 $path = $base_path . DS . $dir;
                 if (is_dir($path)) {
                     if ($this->_checkForModified($directory_structure[$k][$dir], $path, $src_path) === false) {
                         $this->skip_all = true;
                         return;
                     }
                 }
             }
         } else {
             $original_file = $base_path . DS . $node;
             $new_file_location = $this->app_base_dir . str_replace($src_path, '', $original_file);
             if (!file_exists($new_file_location)) {
                 unset($directory_structure[$k]);
             } elseif (md5_file($new_file_location) != md5_file($original_file)) {
                 $message = Ak::t('The file %file exists has local modifications.', array('%file' => $new_file_location));
                 $user_response = AkConsole::promptUserVar($message . "\n k (keep mine), d (delete), a (abort), D (delete all), K (keep all)", 'k');
                 if ($user_response == 'k') {
                     unset($directory_structure[$k]);
                 } elseif ($user_response == 'd') {
                 } elseif ($user_response == 'D') {
                     return false;
                 } elseif ($user_response == 'K') {
                     $directory_structure = array();
                     return false;
                 } elseif ($user_response != 'd') {
                     echo "\nAborting\n";
                     exit;
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
 protected function _checkUninstallDependencies()
 {
     $dependencyFile = $this->app_plugins_dir . DS . $this->plugin_name . DS . 'dependent_plugins';
     if (file_exists($dependencyFile)) {
         $dependendPlugins = file($dependencyFile);
         if (!empty($dependendPlugins)) {
             if (empty($this->options['force'])) {
                 echo "\n";
                 echo Ak::t("The following %plugin %dependent depend on the plugin you are about to uninstall.", array('%plugin' => AkT('plugin', 'quantify(' . count($dependendPlugins) . ')'), '%dependent' => AkT($dependendPlugins, 'toSentence')));
                 echo Ak::t("Please uninstall the dependent %plugin first.", array('%plugin' => AkT('plugin', 'quantify(' . count($dependendPlugins) . ')')));
                 echo "\n";
                 $this->transactionFail();
                 die;
             } else {
                 echo "\n";
                 echo Ak::t("The following %plugin %dependent depend on the plugin you are about to uninstall.", array('%plugin' => AkT('plugin', 'quantify(' . count($dependendPlugins) . ')'), '%dependent' => AkT($dependendPlugins, 'toSentence')));
                 echo "\n";
                 $uninstall = AkConsole::promptUserVar('Are you sure you want to continue uninstalling (Answer with Yes)? The other plugins will malfunction.', array('default' => 'N'));
                 if ($uninstall != 'Yes') {
                     echo Ak::t('Uninstall cancelled.');
                     echo "\n";
                     $this->transactionFail();
                     die;
                 } else {
                     return true;
                 }
             }
         }
         return true;
     }
 }
Exemplo n.º 8
0
function prompt_var($question, $default_value = null, $cli_value = null)
{
    global $options;
    if (empty($options['interactive']) && isset($cli_value)) {
        return $cli_value;
    } else {
        return AkConsole::promptUserVar($question, array('default' => $default_value, 'optional' => true));
    }
}
Exemplo n.º 9
0
        $directory_candidate = $v;
    }
}
$directory = AkelosAppInstaller::getAbsolutePath(get_command_value($options, 'd', 'directory', $directory_candidate, 'Destination directory can\'t be blank'));
$public_html = get_command_value($options, 'p', 'public_html', false);
$public_html = empty($public_html) ? false : AkelosAppInstaller::getAbsolutePath($public_html);
$force = get_command_value($options, 'f', 'force', false);
$quiet = get_command_value($options, 'q', 'quiet', false);
$skip = get_command_value($options, 's', 'skip', false);
$prompt = get_command_value($options, 'prompt', 'prompt', true);
if ($prompt) {
    echo "\nCreate an Akelos " . AKELOS_VERSION . " application in {$directory}\n";
    if ($public_html) {
        echo "symlink the public directory to {$public_html}\n";
    }
    if ($force) {
        "OVERWRITE EXISTING FILES in {$directory}\n";
    }
    AkConsole::promptUserVar("Shall web proceed installing? \nPress enter to continue", array('optional' => true));
}
$Installer = new AkelosAppInstaller(array('directory' => $directory, 'public_html' => $public_html, 'public_html' => $public_html, 'force' => $force, 'quiet' => $quiet, 'skip' => $skip, 'prompt' => $prompt));
$Installer->install();
if (!$quiet) {
    if ($Installer->hasErrors()) {
        echo "\nThere where some errors during the installation process:\n";
        echo "\n * " . join("\n    * ", $Installer->getErrors());
    } elseif (empty($Installer->options['force'])) {
        echo "\n    In order to create the config.php file and setup a database...\n\n" . " change to \n\n    {$directory}\n" . " and run \n\n    ./script/configure \n\nto configure the database details\n";
    }
    echo "\n";
}