Changeset 303

Show
Ignore:
Timestamp:
08/02/07 12:49:01 (1 year ago)
Author:
bermiferrer
Message:

This is a big patch provided by salavert that fixes the issues that prevented the unit tests from passing on Windows environments.
It closes #27 and #28.

  • Fixing non-standard mime type detection under windows.
  • Improving DB connection identifier for handling multiple database connections simultaneously.
  • Improving the migrations versioning scheme. Now versions belong to an specific environment and are stored at app/installers/versions, so you might need to change your existing app/installers/*_version.txt files to app/installers/versions/ENVIRONMENT_*_version.txt
  • Fixed some setup issues on directory recursion where it made the setup script to fail silently.
  • Added rewrite base for testing environments.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/models/framework_setup.php

    r293 r303  
    244244        require_once(AK_APP_DIR.DS.'installers'.DS.'framework_installer.php'); 
    245245 
    246         foreach (array('development', 'production', 'testing') as $mode){ 
     246        foreach (array('production', 'development') as $mode){ 
    247247            $db_conn = Ak::db($this->_getDsn($mode)); 
    248248            $installer = new FrameworkInstaller($db_conn); 
    249             $installer->install(); 
     249            $installer->install(null, array('mode' => $mode)); 
    250250        } 
    251251 
     
    329329%AK_FRAMEWORK_DIR 
    330330 
    331 %AK_ASSET_URL_PREFIX 
    332  
    333331include_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'boot.php'); 
    334332 
     
    362360            $settings['%AK_FRAMEWORK_DIR'] = defined('AK_FRAMEWORK_DIR') ? 
    363361            "defined('AK_FRAMEWORK_DIR') ? null : define('AK_FRAMEWORK_DIR', '".AK_FRAMEWORK_DIR."');" : ''; 
    364  
    365  
    366             $asset_path = $this->_getAssetBasePath(); 
    367             if(!empty($asset_path)){ 
    368                 $settings['%AK_ASSET_URL_PREFIX'] = "define('AK_ASSET_URL_PREFIX','/".trim($this->getUrlSuffix(),'/').'/'.$asset_path."');"; 
    369             }else{ 
    370                 $settings['%AK_ASSET_URL_PREFIX'] = ''; 
    371             } 
    372  
    373362        } 
    374363 
  • trunk/lib/Ak.php

    r296 r303  
    6464    function &db($dsn = null, $connection_id = null) 
    6565    { 
    66         static $db
     66        static $db, $default_connection_id
    6767 
    6868        // In order to retrieve a database connection we just need to provide its identifier 
    69         $connection_id = empty($connection_id) ? 
    70         (empty($dsn) || strstr($dsn,':') ? 'default' : $dsn) : 
    71         $connection_id; 
    72  
     69        if(empty($default_connection_id)){ 
     70            $default_connection_id = md5($dsn); 
     71        } 
     72        $connection_id = empty($connection_id) ? $default_connection_id : $connection_id; 
     73         
    7374        if(empty($db[$connection_id])){ 
    7475            require_once(AK_CONTRIB_DIR.DS.'adodb'.DS.'adodb.inc.php'); 
     
    16491650        ak_compat('mime_content_type'); 
    16501651 
    1651         $mime = mime_content_type($file); 
     1652        $mime = @mime_content_type($file); 
    16521653 
    16531654        if(empty($mime)){ 
    16541655            empty($mime_types) ? require(AK_LIB_DIR.DS.'utils'.DS.'mime_types.php') : null; 
    1655             $file_name = substr($file,strrpos($file,'/')+1); 
    1656             $file_extension = substr($file_name,strrpos($file_name,'.')+1); 
     1656            $file_extension = substr($file,strrpos($file,'.')+1); 
    16571657            $mime = !empty($mime_types[$file_extension]) ? $mime_types[$file_extension] : false; 
    16581658        } 
  • trunk/lib/AkInstaller.php

    r298 r303  
    4949    function install($version = null, $options = array()) 
    5050    { 
     51        $version = (is_null($version)) ? max($this->getAvailableVersions()) : $version; 
     52        return $this->_upgradeOrDowngrade('up',  $version , $options); 
     53    } 
     54 
     55    function up($version = null, $options = array()) 
     56    { 
    5157        return $this->_upgradeOrDowngrade('up', $version, $options); 
    5258    } 
    5359 
    54     function up($version = null, $options = array()) 
    55     { 
    56         return $this->_upgradeOrDowngrade('up', $version, $options); 
    57     } 
    58  
    5960 
    6061    function uninstall($version = null, $options = array()) 
    6162    { 
     63        $version = (is_null($version)) ? 0 : $version; 
    6264        return $this->_upgradeOrDowngrade('down', $version, $options); 
    6365    } 
     
    7779        } 
    7880 
    79         $current_version = $this->getInstalledVersion(); 
     81        $current_version = $this->getInstalledVersion($options); 
    8082        $available_versions = $this->getAvailableVersions(); 
    8183 
     
    8688            $version = isset($version[0]) && is_numeric($version[0]) ? $version[0] : $newest_version; 
    8789            $versions = range($current_version+1,$version); 
    88              
     90 
    8991            if($current_version > $version){ 
    9092                echo Ak::t("You can't upgrade to version %version, when you are currently on version %current_version", array('%version'=>$version,'%current_version'=>$current_version)); 
     
    9597            $versions = range($current_version, empty($version) ? 1 : $version+1); 
    9698 
    97             if($current_version < $version){ 
     99            if($current_version == 0){ 
     100                return true; 
     101            }elseif($current_version < $version){ 
    98102                echo Ak::t("You can't downgrade to version %version, when you just have installed version %current_version", array('%version'=>$version,'%current_version'=>$current_version)); 
    99103                return false; 
     
    153157        $this->transactionComplete(); 
    154158        if($success){ 
    155             $this->setInstalledVersion($version_number); 
     159            $this->setInstalledVersion($version_number, $options); 
    156160        } 
    157161        return $success; 
     
    164168 
    165169 
    166     function _versionPath() 
    167     { 
    168         return AK_APP_DIR.DS.'installers'.DS.$this->getInstallerName().'_version.txt'; 
    169     } 
    170  
    171  
    172     function getInstalledVersion() 
    173     { 
    174         $version_file = $this->_versionPath(); 
     170    function _versionPath($options = array()) 
     171    { 
     172        $mode = empty($options['mode']) ? AK_ENVIRONMENT : $options['mode']; 
     173        return AK_APP_DIR.DS.'installers'.DS.'versions'.DS.$mode.'_'.$this->getInstallerName().'_version.txt'; 
     174    } 
     175 
     176 
     177    function getInstalledVersion($options = array()) 
     178    { 
     179        $version_file = $this->_versionPath($options); 
     180         
    175181        if(!is_file($version_file)){ 
    176             $this->setInstalledVersion(0); 
    177         } 
    178         return Ak::file_get_contents($this->_versionPath()); 
    179     } 
    180  
    181  
    182     function setInstalledVersion($version
    183     { 
    184         return Ak::file_put_contents($this->_versionPath(), $version); 
     182            $this->setInstalledVersion(0, $options); 
     183        } 
     184        return Ak::file_get_contents($this->_versionPath($options)); 
     185    } 
     186 
     187 
     188    function setInstalledVersion($version, $options = array()
     189    { 
     190        return Ak::file_put_contents($this->_versionPath($options), $version); 
    185191    } 
    186192 
     
    317323        $index_name = ($index_name == '') ? 'idx_'.$table_name.'_'.$columns : $index_name; 
    318324        $index_options = array(); 
    319         if (preg_match('/(UNIQUE|FULLTEXT|HASH)/',$columns,$match))
     325        if(preg_match('/(UNIQUE|FULLTEXT|HASH)/',$columns,$match))
    320326            $columns = trim(str_replace($match[1],'',$columns),' '); 
    321327            $index_options[] = $match[1]; 
     
    326332    function removeIndex($table_name, $columns_or_index_name) 
    327333    { 
    328         if (!$this->tableExists($table_name)) return false; 
     334        if(!$this->tableExists($table_name)) return false; 
    329335        $available_indexes =& $this->db->MetaIndexes($table_name); 
    330336        $index_name = isset($available_indexes[$columns_or_index_name]) ? $columns_or_index_name : 'idx_'.$table_name.'_'.$columns_or_index_name; 
    331         if (!isset($available_indexes[$index_name]))
     337        if(!isset($available_indexes[$index_name]))
    332338            trigger_error(Ak::t('Index %index_name does not exist.', array('%index_name'=>$index_name)), E_USER_NOTICE); 
    333339            return false; 
     
    408414            if(strstr($columns,"\n")){ 
    409415                $columns = explode("\n",$columns); 
    410             }elseif (strstr($columns,',')){ 
     416            }elseif(strstr($columns,',')){ 
    411417                $columns = explode(',',$columns); 
    412418            } 
     
    437443            if(is_string($replacement)){ 
    438444                $column = preg_replace($regex,$replacement,$column); 
    439             }elseif (preg_match($regex,$column,$match)){ 
     445            }elseif(preg_match($regex,$column,$match)){ 
    440446                $column = call_user_func_array($replacement,$match); 
    441447            } 
  • trunk/script/setup

    r293 r303  
    126126    { 
    127127        foreach($this->source_tree as $k=>$node){ 
    128             $folder = array_shift(array_keys($node)); 
    129             $path = $this->options['directory'].DS.$folder; 
    130             if(is_dir($path) && !file_exists($path.DS.'.htaccess') && $folder != 'public'){ 
    131                 file_put_contents($path.DS.'.htaccess', "order allow,deny\ndeny from all"); 
    132             } 
    133         } 
    134  
     128            if (is_array($node)){ 
     129                $folder = array_shift(array_keys($node)); 
     130                $path = $this->options['directory'].DS.$folder; 
     131                if(is_dir($path) && !file_exists($path.DS.'.htaccess') && $folder != 'public'){ 
     132                    file_put_contents($path.DS.'.htaccess', "order allow,deny\ndeny from all"); 
     133                } 
     134            } 
     135        } 
    135136    } 
    136137 
  • trunk/test/fixtures/config/config.php

    r278 r303  
    2020(array)@explode('/',@$_SERVER['REQUEST_URI']))),DIRECTORY_SEPARATOR),array('','/'),AK_TEST_DIR)); 
    2121 
    22 defined('AK_ENABLE_AKELOS_ARGS') ? null : define('AK_ENABLE_AKELOS_ARGS', true);  
     22defined('AK_ENABLE_AKELOS_ARGS') ? null : define('AK_ENABLE_AKELOS_ARGS', true); 
    2323//define('AK_SKIP_DB_CONNECTION',isset($db) && $db === false); 
    2424 
     
    3030 
    3131defined('AK_TESTING_URL') ? null : define('AK_TESTING_URL', rtrim(AK_URL,'/').'/test/fixtures/public'); 
     32defined('AK_TESTING_REWRITE_BASE') ? null : define('AK_TESTING_REWRITE_BASE', false); 
    3233 
    3334defined('AK_LIB_TESTS_DIRECTORY') ? null : define('AK_LIB_TESTS_DIRECTORY', AK_TEST_DIR.DS.'unit'.DS.'lib'); 
     35 
     36if(AK_TESTING_REWRITE_BASE){ 
     37    Ak::file_put_contents(AK_BASE_DIR.'/test/fixtures/public/.htaccess', str_replace('# RewriteBase /test/fixtures/public','RewriteBase '.AK_TESTING_REWRITE_BASE, Ak::file_get_contents(AK_BASE_DIR.'/test/fixtures/public/.htaccess'))); 
     38} 
    3439 
    3540if(defined('AK_TEST_DATABASE_ON')){ 
  • trunk/test/unit/lib/AkActiveRecord/_AkActiveRecord_3.php

    r217 r303  
    284284    function Test_of_binary_data_on_database() 
    285285    { 
    286         $long_string = Ak::file_get_contents(AK_LIB_DIR.DS.'AkActiveRecord.php'); 
     286        $long_string = file_get_contents(AK_LIB_DIR.DS.'AkActiveRecord.php'); 
    287287 
    288288        $_tmp_file = fopen(AK_LIB_DIR.DS.'AkActiveRecord.php', "rb"); 
  • trunk/test/unit/lib/utils/_Ak_file_functions.php

    r296 r303  
    103103    function test_mime_type_detection() 
    104104    { 
    105         $this->assertEqual(Ak::mime_content_type(AK_PUBLIC_DIR.DS.'images'.DS.'akelos_framework_logo.png'),'image/png'); 
     105        // png is not in any RFC so we might want to check if it has a /x- preffix for non standard values 
     106        $this->assertTrue(in_array(Ak::mime_content_type(AK_PUBLIC_DIR.DS.'images'.DS.'akelos_framework_logo.png'),array('image/png','image/x-png'))); 
    106107        $this->assertEqual(Ak::mime_content_type('C:\Folder\image.png'),'image/png'); 
     108    } 
     109 
     110    function test_should_read_files_using_scoped_file_get_contents_function() 
     111    { 
     112        $this->assertEqual(Ak::file_get_contents(AK_LIB_DIR.DS.'AkActiveRecord.php'), file_get_contents(AK_LIB_DIR.DS.'AkActiveRecord.php')); 
    107113    } 
    108114