示例#1
0
 function createTableOnTheFly($model_name, $fields)
 {
     $table_name = AkInflector::tableize($model_name);
     $Installer = new AkInstaller();
     $Installer->dropTable($table_name, array('sequence' => true));
     $Installer->createTable($table_name, $fields, array('timestamp' => false));
 }
示例#2
0
 public function setup()
 {
     $this->installAndIncludeModels(array('Post', 'Tag', 'Comment'));
     $Installer = new AkInstaller();
     @$Installer->dropTable('posts_tags');
     @Ak::file_delete(AK_MODELS_DIR . DS . 'post_tag.php');
 }
示例#3
0
 function test_start()
 {
     $this->installAndIncludeModels(array('Post', 'Tag'));
     $Installer = new AkInstaller();
     @$Installer->dropTable('posts_tags');
     @Ak::file_delete(AK_MODELS_DIR . DS . 'post_tag.php');
     $this->installAndIncludeModels(array('Picture', 'Thumbnail', 'Panorama', 'Property', 'PropertyType'));
 }
示例#4
0
    public function hasCollisions()
    {
        $this->collisions = array();
        $user_answer = 5;
        foreach (array_values($this->files) as $file_name){
            if($user_answer != 3 && file_exists($file_name)){
                if($user_answer == 4){
                    $this->_skip_files[] = $file_name;
                    continue;
                }
                $message = Ak::t('%file_name file already exists',array('%file_name'=>$file_name));
                $user_answer = (int)AkInstaller::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){
                    die("Aborted\n");
                }
            }
        }
        return count($this->collisions) > 0;
    }
 public function test_should_crud_using_conflictive_column_names()
 {
     $this->installAndIncludeModels(array('Exist' => 'id,order,index, updated_at'));
     $Installer = new AkInstaller();
     $this->assertTrue($Installer->tableExists('exists'));
     $Exist = new Exist();
     $Same = $Exist->create(array('order' => 'order_value', 'index' => 'index_value'));
     $this->assertTrue(!$Same->isNewRecord());
     $this->assertTrue($Exist->findFirstBy($Same->getId()));
     $last_update = $Same->get('updated_at');
     $Same->save();
     $this->assertNotEqual($last_update, $Same->get('updated_at'));
     $id = $Same->getId();
     $Same->destroy();
     $this->assertFalse($Exist->findFirstBy($id, array('default' => false)));
 }
 public function test_should_migrate_integers()
 {
     if (!$this->WeHaveAPostgreSqlEnvironment) {
         return;
     }
     // mimic OLD boolean and integer behavior!
     $this->installAndIncludeModels(array('TestPage' => "id,parent_id n(11.0),is_public n(1)"));
     $from_datadict = $this->db->getColumnDetails('test_pages');
     $this->assertEqual($from_datadict['PARENT_ID']->type, 'numeric');
     $this->assertEqual($from_datadict['PARENT_ID']->max_length, 11);
     $this->assertEqual($from_datadict['PARENT_ID']->scale, 0);
     $this->assertEqual($from_datadict['IS_PUBLIC']->type, 'numeric');
     $this->assertEqual($from_datadict['IS_PUBLIC']->max_length, 1);
     $this->assertEqual($from_datadict['IS_PUBLIC']->scale, 0);
     // we insert some data, not using ActiveRecord
     $this->db->execute('INSERT INTO test_pages (is_public) VALUES (1)');
     $this->db->execute('INSERT INTO test_pages (is_public) VALUES (0)');
     $this->db->execute('INSERT INTO test_pages (parent_id) VALUES (1)');
     // we want is_public = NULL
     $data = $this->db->select('SELECT * FROM test_pages');
     $expected = array(array('id' => 1, 'parent_id' => null, 'is_public' => 1), array('id' => 2, 'parent_id' => null, 'is_public' => 0), array('id' => 3, 'parent_id' => 1, 'is_public' => null));
     $this->assertEqual($data, $expected);
     // now we migrate
     $installer = new AkInstaller();
     $installer->transactionStart();
     // if the following fails, you're on Postgre 7 and you have to do it just like we'll do it with the boolean-field
     // except you can use the CAST-function:
     // UPDATE test_pages SET parent_id_temp = CAST(parent_id AS integer)
     $installer->execute('ALTER TABLE test_pages ALTER COLUMN parent_id TYPE integer');
     $installer->addColumn('test_pages', 'is_public_temp boolean');
     $installer->execute('UPDATE test_pages
          SET is_public_temp =
                  CASE is_public
                    WHEN 0 THEN false
                    WHEN 1 THEN true
                    ELSE NULL
                  END');
     $installer->removeColumn('test_pages', 'is_public');
     $installer->renameColumn('test_pages', 'is_public_temp', 'is_public');
     $installer->transactionComplete();
     // let's see what we got
     $from_datadict = $this->db->getColumnDetails('test_pages');
     $this->assertEqual($from_datadict['PARENT_ID']->type, 'int4');
     $this->assertEqual($from_datadict['IS_PUBLIC']->type, 'bool');
     $data = $this->db->select('SELECT * FROM test_pages');
     $expected = array(array('id' => 1, 'parent_id' => null, 'is_public' => 't'), array('id' => 2, 'parent_id' => null, 'is_public' => 'f'), array('id' => 3, 'parent_id' => 1, 'is_public' => null));
     $this->assertEqual($data, $expected);
     // ok, we're done
     $installer->dropTable('test_pages');
 }
示例#7
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 AkInstaller::promptUserVar($question, array('default' => $default_value, 'optional' => true));
    }
}
示例#8
0
 public function generate()
 {
     $Installer = new AkInstaller();
     $vars['github'] = $Installer->promptUserVar('Github user and project (optional) [user project]', array('optional' => true, 'default' => false));
     if (!empty($vars['github'])) {
         list($user, $project) = explode(' ', $vars['github'] . ' ');
         //$vars['git'] = "git@github.com:$user/$project.git";
         $vars['git'] = "git://github.com/{$user}/{$project}.git";
         $vars['github'] = "http://github.com/{$user}/{$project}/";
     }
     if (empty($vars['git'])) {
         $vars['git'] = $Installer->promptUserVar('Git repository (git@git.example.com:repository_name.git)');
     }
     $vars['email'] = $Installer->promptUserVar('Notification email');
     foreach ($vars as $k => $v) {
         $this->assignVarToTemplate($k, $v);
     }
     $this->save($this->destination_path . DS . 'config.xml', $this->render('config'));
     $this->save($this->destination_path . DS . 'nextBuildNumber', $this->render('nextBuildNumber'));
     @mkdir($this->destination_path . DS . 'builds');
     @mkdir($this->destination_path . DS . 'workspace');
 }
示例#9
0
    function relativizeStylesheetPaths()
    {
        $url_suffix = AkInstaller::promptUserVar('The admin plugin comes with some fancy CSS background images.

Your aplication might be accesible 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", @Ak::file_get_contents($filename));
                !empty($relativized_css) && @Ak::file_put_contents($filename, $relativized_css);
            }
        }
    }
示例#10
0
 function drop($table_name)
 {
     $Installer = new AkInstaller();
     $Installer->dropTable($table_name);
     $this->assertFalse(self::table_exists($table_name));
 }
示例#11
0
 static function uninstall()
 {
     $db = Ak::db();
     if ($db->tableExists('sessions')) {
         $Installer = new AkInstaller($db);
         $Installer->dropTable('sessions');
     }
 }
示例#12
0
 public function test_should_remove_associated_using_the_right_key()
 {
     $Installer = new AkInstaller();
     @$Installer->dropTable('groups_users');
     @Ak::file_delete(AK_MODELS_DIR . DS . 'group_user.php');
     $this->installAndIncludeModels('User', 'Group', array('instantiate' => true));
     $Admin =& $this->Group->create(array('name' => 'Admin'));
     $Moderator =& $this->Group->create(array('name' => 'Moderator'));
     $this->assertFalse($Admin->hasErrors());
     $this->assertFalse($Moderator->hasErrors());
     $Salavert =& $this->User->create(array('name' => 'Jose'));
     $this->assertFalse($Salavert->hasErrors());
     $Salavert->group->setByIds($Admin->getId(), $Moderator->getId());
     $Salavert =& $this->User->find($Salavert->getId());
     $this->assertEqual(2, $Salavert->group->count());
     $Jyrki =& $this->User->create(array('name' => 'Jyrki'));
     $this->assertFalse($Jyrki->hasErrors());
     $Jyrki->group->setByIds($Admin->getId(), $Moderator->getId());
     $Jyrki =& $this->User->find($Jyrki->getId());
     $this->assertEqual(2, $Jyrki->group->count());
     $Jyrki->destroy();
     $Salavert =& $this->User->find($Salavert->getId());
     $this->assertEqual(2, $Salavert->group->count());
 }
示例#13
0
 function _checkUninstallDependencies()
 {
     $dependencyFile = AK_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 = AkInstaller::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;
     }
 }
示例#14
0
<?php

# This file is part of the Akelos Framework
# (Copyright) 2004-2010 Bermi Ferrer bermi a t bermilabs com
# See LICENSE and CREDITS for details
$Installer = new AkInstaller();
$Installer->removeFilesFromApp(dirname(__FILE__) . DS . 'website_files');
示例#15
0
 public function __construct($db_connection = null, $plugin_name = '')
 {
     parent::__construct($db_connection);
     $this->plugin_name = $plugin_name;
 }
示例#16
0
 public function _createJoinTable()
 {
     $options = $this->getOptions($this->association_id);
     require_once AK_LIB_DIR . DS . 'AkInstaller.php';
     $Installer = new AkInstaller();
     $Installer->createTable($options['join_table'], "id,{$options['foreign_key']},{$options['association_foreign_key']}", array('timestamp' => false));
     return $this->JoinObject->setTableName($options['join_table'], false);
 }
示例#17
0
文件: sessions.php 项目: bermi/akelos
<?php

define('AK_SESSION_HANDLER', 1);
if (isset($_GET['expire'])) {
    define('AK_SESSION_EXPIRE', (int) $_GET['expire']);
}
require_once dirname(__FILE__) . '/../config.php';
Ak::db();
if (!empty($_GET['construct'])) {
    @AkDbSession::install();
    @AkAdodbCache::install();
} elseif (!empty($_GET['destruct'])) {
    AkAdodbCache::uninstall();
    AkDbSession::uninstall();
    $Installer = new AkInstaller();
    $Installer->dropTable('akelos_migrations');
}
$session_handler = isset($_GET['handler']) ? $_GET['handler'] : null;
$session_settings = Ak::getSettings('sessions', false);
if ($session_handler !== null) {
    $session_settings['handler']['type'] = (int) $session_handler;
}
error_reporting(E_STRICT);
$SessionHandler = AkSession::lookupStore($session_settings);
session_start();
if (isset($_GET['key']) && isset($_GET['value'])) {
    $_SESSION[$_GET['key']] = $_GET['value'];
} elseif (isset($_GET['key'])) {
    if (isset($_SESSION[$_GET['key']])) {
        echo $_SESSION[$_GET['key']];
    } else {
 public function __construct()
 {
     $adapter = AkDbAdapter::getInstance('sqlite_databases', true, 'database');
     parent::__construct($adapter);
 }
示例#19
0
文件: akismet.php 项目: joeymetal/v1
<?php

error_reporting(E_ALL);
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
require_once(dirname(__FILE__).str_repeat(DS.'..', 5).DS.'test'.DS.'fixtures'.DS.'config'.DS.'config.php');
require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'AkActionViewHelper.php');

require_once(AK_LIB_DIR.DS.'AkInstaller.php');


!defined('AK_AKISMET_API_KEY') && define('AK_AKISMET_API_KEY', (!empty($argv[1])?$argv[1]:AkInstaller::promptUserVar('Akismet API key')));
!defined('AK_AKISMET_SITE_URL') && define('AK_AKISMET_SITE_URL', (!empty($argv[2])?$argv[2]:AkInstaller::promptUserVar('Akismet site URL')));

require_once(dirname(__FILE__).DS.'..'.DS.'lib'.DS.'akismet_helper.php');

class AkismetHelperTestCase extends AkUnitTest
{
    function test_setup()
    {
        $this->akismet_helper =& new AkismetHelper();
    }

    function test_should_verify_key()
    {
        $this->assertTrue($this->akismet_helper->verifyKey());
    }

    function test_should_detect_spam()
    {
        $this->assertTrue($this->akismet_helper->isSpam(
        'this author triggers known spam' , array(
示例#20
0
文件: base.php 项目: bermi/akelos
 public function dropTables($tables = array())
 {
     $installer = new AkInstaller();
     if (is_string($tables) && $tables == 'all') {
         $tables = Ak::db()->getAvailableTables();
     }
     foreach ($tables as $table) {
         $installer->dropTable($table, array('sequence' => true));
     }
 }
 function __construct()
 {
     $adapter =& AkDbAdapter::getInstance('sqlite_databases');
     parent::AkInstaller($adapter);
 }
示例#22
0
<?php

# This file is part of the Akelos Framework
# (Copyright) 2004-2010 Bermi Ferrer bermi a t bermilabs com
# See LICENSE and CREDITS for details
$Installer = new AkInstaller();
$Installer->copyFilesIntoApp(dirname(__FILE__) . DS . 'website_files', array('relative_url' => $Installer->promptUserVar("Relative url path for serving images on CSS files\n    (ie. /public /akelos/public or /)\n hit enter if your application is served from the base of hostname\n", '/')));
echo "\nYou can now browse your documentation from localhost at: \n\n    " . AK_SITE_URL . "/docs\n\nPlease configure access settings by editing docs_controller.php\n";
示例#23
0
    /**
     * Promts for a variable on console scripts
     */
    function promptUserVar($message, $options = array())
    {
        $f = fopen("php://stdin","r");
        $default_options = array(
        'default' => null,
        'optional' => false,
        );

        $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 AkInstaller::promptUserVar($message, $options);
        }
        fclose($f);
        return empty($value) ? $options['default'] : $value;
    }