Development

#4522 (generateFile = true - dangerous implementation)

You must first sign up to be able to contribute.

Ticket #4522 (closed defect: invalid)

Opened 6 years ago

Last modified 5 years ago

generateFile = true - dangerous implementation

Reported by: rande Assigned to: Jonathan.Wage
Priority: major Milestone:
Component: sfDoctrinePlugin Version:
Keywords: Cc:
Qualification: Unreviewed

Description

Let's use this schema as an example

swPage:
  tableName: sw_cms_pages
  columns:
    route: string(255)
    title: string(255)
    format: string(10)
    content: clob
    script: clob
    css: clob
    
  actAs:
    I18n:
      tableName: sw_cms_page_translations
      fields: [content, title, slug]
      generateFiles: true
      generatePath: <?php echo sfConfig::get('sf_lib_dir') ?>/model/doctrine/translations
      actAs: 
        Sluggable:
         field: [title]
         builder: [ swTranslationPage, buildUrl ]
    
    Timestampable:
    NestedSet:
      hasManyRoots: true

The result of ./symfony doctrine:build-model is 2 files : swPage and swPageTable.

When fetching the first page:

    $sw_page = Doctrine_Query::Create()
      ->select('swPage.*')
      ->from('swPage')
      ->leftJoin('swPageTranslation')
      ->where('swPageTranslation.lang = ? and swPageTranslation.slug = ?', array($culture, $slug))
      ->fetchOne();

Doctrine generated 2 files : swPageTranslation and BaseswPageTranslation?. The last file is overwritten at every request when the model is loaded. Of course just after, symfony bugs as the sfAutoloader does not known where BaseswPageTranslation? is ... a 'symfony cc' fix this problem.

Anothers problems :

  • the generatePath is hardcoded (maybe my example is wrong, but how can I do differently ?)
  • the generated files have webserver permission.

So I think the implementation is wrong :

  • the symfony task (or doctrine sub task) should create all files (with translation when generateFiles is set to true)
  • the webserver should not recreated files at every request !
  • the generatedPath should be optional at the symfony layer and not hardcoded into the model (which breaks deployment)

Change History

10/01/08 14:05:10 changed by rande

  • owner changed from jwage to Jonathan.Wage.

10/03/08 09:20:38 changed by rande

There is another issue while working with generated file in this case. The Translation key are not the 'lang' field but an integer. To fix that I have to add this piece of code :

class swPageTranslation extends BaseswPageTranslation
{
  public function construct()
  {
    parent::construct();
    $this->bindQueryParts(array('indexBy' => 'lang'));
  }
}

Note : the setup method is not called.

11/06/08 21:21:38 changed by Jonathan.Wage

This belongs in the Doctrine trac.

11/06/08 21:21:47 changed by Jonathan.Wage

  • status changed from new to closed.
  • resolution set to invalid.