Author Archive

Symfony 1.4: Doctrine: There is no open connection

When you have this problem just go into your controler e.g. index.php and add the following line:


$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'test', true);
new sfDatabaseManager($configuration);


Symfony: Instruct browser to refresh CSS and JS files

In Symfony the stylesheets and javascript files are defined in the view.yml. Sometimes the problem appears that the browsers cache these files, even if there where some changes in the last release without refreshing the new contents.

There is a common technique to instruct the browser to take the new file version: Browsers store different file versions for different GET paramters. So if you include a CSS file like this:

<script type="text/javascript" src="css/styles.css?v=21"></script>

and in the next version with a higher version number (v=22), the browser will use  (and cache) the newer version.

In our case we save the current version number (SVN) into the app.yml and we use this number as increasing GET-Parameter to force a cache refresh:

default:
  stylesheets: [styles.css?v=<?php echo sfConfig::get('app_revision'); ?>]

Symfony cache folder on Windows Azure

I had the problem, that symfony had no write permissons to create the cache files in the Windows Azure approot folder.

After some research I found out, that it is possible to allocate local storage where the role user has write permissions. The disadvantage though is, that the local storage is not persistent, that means, it will be reset after role upgrades, instance reimage or reboots. But for caching I don’t need a persistent storage.

To get it running you need the folowing settings:

ServiceDefinition.csdef

Define a local resource, in this case with the folder name “FileCacheStorage” and the size 1000MB:

<?xml version="1.0" encoding="UTF-8"?>
<ServiceDefinition name="MyWebRole" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WebRole enableNativeCodeExecution="true" name="WebRole" vmsize="ExtraSmall">
    ...
    <LocalResources>
      <LocalStorage name="FileCacheStorage" sizeInMB="1000" />
    </LocalResources>
 </WebRole>
</ServiceDefinition>

ProjectConfiguration.class.php

Change the default symfony cache path within the “setup()” method:

    if(strpos($_SERVER['HTTP_HOST'], "127.0.0.1")===false)
    {
    	$azureFileCachePath = substr($_SERVER['TEMP'], 0, 3).'Resources\Directory\\'.$_SERVER['RoleDeploymentID'].'.WebRole.FileCacheStorage\\cache';
    	$azureFileLogPath   = substr($_SERVER['TEMP'], 0, 3).'Resources\Directory\\'.$_SERVER['RoleDeploymentID'].'.WebRole.FileLogStorage\\log';

		  // Replace default path with local azure storage path, defined in ServiceDefinition ("LocalStorage" = "FileCacheStorage"):
		  $this->setCacheDir($azureFileCachePath);
    }

Notice: When you are testing in your local dev environment the local storage path is completely different (more information here), so I decided to change the path only in the cloud env, because locally I have no write problems. To get the recent drive letter I take it from $_SERVER['TEMP'].

(For the symonfy logging I did it the same way.)

Special thanks to Taylor for his hints.

I hope this helps somebody ;)

Links

 


Symfony 1.4: Doctrine and SQL Azure

 

To get your SQL Azure DB running with Symony 1.4 and Doctrine 1.2.4 you need to make the following changes:

In databases.yml:

all:
  doctrine:
    class: sfDoctrineDatabase
    param:
      dsn:      odbc:DRIVER={SQL Server Native Client 10.0};Server=SERVER.database.windows.net;Database=DATABASE;Encrypt=yes;
      username: USERNAME@SERVER
      password: PASSWORD

Sadly there appeard some ugly errors, but I could fix them (please don’t ask me how I found the solutions).

The first error appeared trying to build the model:

When using the attribute ATTR_AUTO_ACCESSOR_OVERRIDE you cannot use the field name “defaultculture” because it is reserved by Doctrine. You must cho
ose another field name.

In my case it’s not possible to change the field name because the DB schema is not under my control. To solve this I did the follwing changes:

In symfony/lib/plugins/sfDoctrinePlugin/config/sfDoctrinePluginConfiguration.class.php deactivate the setting ATTR_AUTO_ACCESSOR_OVERRIDE:

$manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, false);

And in symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Import/Mssql.php I had to change:

    public function listTableColumns($table)
    {
        #$sql = 'EXEC sp_primary_keys_rowset @table_name = ' . $this->conn->quoteIdentifier($table, true);
        $sql = 'EXEC sp_pkeys @table_name = ' . $this->conn->quoteIdentifier($table, true);

The changes inside the Doctrine Plugin are not clean, it should be an accrodingly extension, but it worked for my quick requirement to generate a schema out of the database.

EDIT:

For some reason I got again an error while trying to build the schema out of the SQL Azure database:

SQLSTATE[42000]: Syntax error or access violation: 156 [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near the keyword ‘File’. (SQLExecute[156] at ext\pdo_odbc\odbc_stmt.c:254). Failing Query: “EXEC sp_pkeys @table_name = File”

and

SQLSTATE[42000]: Syntax error or access violation: 156 [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near the keyword ‘File’. (SQLExecute[156] at ext\pdo_odbc\odbc_stmt.c:254). Failing Query: “EXEC sp_columns @table_name = File”

To solve the problem I need to modifie the change I did in

symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Import/Mssql.php:

    public function listTableColumns($table)
    {
        #$sql = 'EXEC sp_primary_keys_rowset @table_name = ' . $this->conn->quoteIdentifier($table, true);
        $sql = 'EXEC sp_pkeys @table_name = ' . $this->conn->quoteIdentifier($table, false);
        ...
        #$sql     = 'EXEC sp_columns @table_name = ' . $this->conn->quoteIdentifier($table, true);
        $sql     = 'EXEC sp_columns @table_name = ' . $this->conn->quoteIdentifier($table, false);

I changed the 2nd quoteIdentifier parameter to “false“.


Eclipse: javax.crypto.BadPaddingException

Today I just wanted to add the Windows Azure Certificate to my Eclipse IDE (WindowsAzure4e).
I misstyped the cert password and get this error:

javax.crypto.BadPaddingException: Given final block not properly padded

But then I didn’t get the dialog again to enter the right password.

To get this problem solved you need to delete the imported windows azure certs settings in eclipse.

To do so just delete this folder:

ECLIPSE_WORKSPACE/.metadata/.plugins/org.soyatec.windows.azure.core

Then you can repeat adding the certificate.

Maybe it also helps to delete the certificate completely from your system. To do so start the windows cert manger:

Start -> Search -> certmgr.msc -> Enter

Search for the installed cert in the different cert folders and delete it.


Copyright © 1996-2010 iTopiaBlog. All rights reserved.
Jarrah theme by Templates Next | Powered by WordPress