2015-12-01 1 views
7

次の設定のZF2プロジェクトがあります。 Doctrine ORMとSlmQueueを使用しています。 SlmQueueは私たちの命名規則とOracleデータベースをサポートしていないため、SlmQueueDoctrineをカスタマイズしました。ZF2、Oracle、SlmQueueDoctrine、ClearObjectManagerStrategyが機能しません。

自分のジョブがClearObjectManagerStrategyを使用していないと思われ、個々のジョブの実行前にObjectManagerをクリアしません。

キュー起動後のDBの変更は反映されません。しかし、キューデーモンを停止して再起動すると、新しい値が選択されます。

個々のジョブの実行前にClearObjectManagerStrategyを実装し、ObjectManagerをクリアするにはどうすればよいですか?

私は運がなくても多くの人にアプローチしました。

composer.json

{ 
    "repositories": [ 
     { 
      "url": "https://github.com/pradeep-sanjaya/doctrine-extensions.git", 
      "type": "git" 
     } 
    ], 
    "require": { 
     "php": ">=5.3.3", 
     "zendframework/zendframework": "2.3.3", 
     "doctrine/doctrine-orm-module": "0.7.*", 
     "pradeep-sanjaya/doctrine-extensions": "dev-master", 
     "spoonx/sxmail": "1.4.*", 
     "slm/locale": "dev-master", 
     "imagine/Imagine": "0.6.*", 
     "tecnick.com/tcpdf": "dev-master", 
     "slm/queue": "0.4.*", 
     "slm/queue-doctrine": "0.4.*" 
    } 
} 

設定/自動読み込み/ slm_queue.local.php

<?php 
return array(
    'slm_queue' => array(
     'queue_manager' => array(
      'factories' => array(
       'doctrineQueue' => 'SlmQueueDoctrine\Factory\DoctrineQueueFactory' 
      ), 
     ), 
     'job_manager' => array(
      'factories' => array(
       'Report\Job\Rank' => 'Report\Job\RankFactory', 
      ), 
      'shared' => array(
       'Report\Job\Rank' => false 
      ), 
     ), 
     'queues' => array(
      'doctrineQueue' => array(
       'table_name' => 'IOQUEUE' 
      ) 
     ) 
    ) 
); 
?> 

モジュール/レポート/ SRC /レポート/仕事/ Rank.php

<?php 
namespace Report\Job; 

use DoctrineModule\Persistence\ObjectManagerAwareInterface; 
use DoctrineModule\Persistence\ProvidesObjectManager as ProvidesObjectManagerTrait; 
use SlmQueue\Job\AbstractJob; 

use Application\Entity\Report; 

use Application\Log\LoggerAwareInterface; 
use Application\Log\LoggerAwareTrait; 

use Application\Service\ReportService; 

class Rank extends AbstractJob implements ObjectManagerAwareInterface, LoggerAwareInterface 
{ 
    use LoggerAwareTrait; 
    use ProvidesObjectManagerTrait; 

    /** 
    * @var ReportService 
    */ 
    protected $reportService; 

    /** 
    * @var array 
    */ 
    protected $reportId = array(); 

    public function setReportService(ReportService $reportService) 
    { 
     $this->reportService = $reportService; 
    } 

    /** 
    * Execute the job 
    * 
    * @return void 
    */ 
    public function execute() 
    { 
     //clear object manager does not work 
     //$om = $this->getObjectManager(); 
     //$om->clear(); 

     $content = $this->getContent(); 
     $this->setReportId($content['reportId']); 

     if (!empty($this->reportId)) { 
      try { 
       if (is_array($this->reportId)) { 
        foreach ($this->reportId as $reportId) { 
         $this->updateRank($reportId); 
        } 
        unset($reportId); 
       } else { 
        $this->updateRank($this->reportId); 
       } 
      } catch (\Exception $exception) { 
       echo "Exception message is {$exception->getMessage()} \n"; 
      } 
     } 
    } 

    private function updateRank($reportId) 
    { 
     /* @var $report Report */ 
     $report = $this->reportService->getReport($reportId); 
     $this->logInfo(print_r($report, true)); // this always return older db values, the values before it start queue deamon 

     if (!$report instanceof Report) { 
      return; 
     } 

     if (empty($rankData)) { 
      return; 
     } 

     //more codes, application related logics 

     $this->reportService->updateReportEntity($report); 
    } 

    private function setReportId($reportId) 
    { 
     if (is_numeric($reportId)) { 
      $this->reportId = array($reportId); 
     } elseif (is_array($reportId)) { 
      $this->reportId = $reportId; 
     } else { 
      throw new \Exception('Expects reportId as int or array'); 
     } 
    } 
} 
+0

*「オブジェクトマネージャがクリアされません」とはどういう意味ですか?間違いはありますか?エラーは何ですか? 'ObjectManager'は設定されていませんか?あなたは 'ObjectManager'をどこに注入しますか?私はそれがフラッシュオブジェクトマネージャの現在のトランザクション – Wilt

+0

実装ObjectManagerAwareInterfaceを参照してProvidesObjectManagerを使用して、あなたが工場 –

+0

コメント行からのObjectManagerを注入することができません動作は個々のジョブの実行前に明確なObjectManagerです。私は、ジョブを実行する前に、だから、私はテーブルからの結果を更新されます。 –

答えて

3

それが明らかに完全ではないことを意味する場合は、明らかにthis is not a bugが期待された動作です。

あなたはclearメソッドの呼び出しに行動のためのthe documentation chapter 7.5.を確認することができますときにはEntityManager#クリア()

は、現在、EntityManagerインスタンスによって管理されているすべてのエンティティが外れ、呼び出されます。 your comment

あなたは「それはフラッシュオブジェクトマネージャの現在のトランザクションない」と述べました。これは明確な呼び出しから期待できる動作ではありません。 、

デタッチ操作の意味エンティティXに適用される次のとおりです。:マニュアルに従って、次のアクションで結果を切り離し

  • Xが管理エンティティ、デタッチ操作の原因である場合それは分離される。デタッチ操作は、Xからこれらの他のエンティティへの関係がcascade = DETACHまたはcascade = ALL(「推移的永続性」を参照)とマッピングされている場合、Xによって参照されるエンティティにカスケードされます。以前にXを参照していたエンティティは、引き続きXを参照します。
  • Xが新しいエンティティまたはデタッチされたエンティティの場合、デタッチ操作で無視されます。
  • Xが削除されたエンティティの場合、Xからこれらの他のエンティティへの関係がcascade = DETACHまたはcascade = ALL(「推移永続性」を参照)とマッピングされている場合、Xによって参照されるエンティティにデタッチ操作がカスケードされます。以前にXを参照していたエンティティは、引き続きXを参照します。
+0

は私の期待しないわけ「は動作しません明確なオブジェクトマネージャ」コンストラクタ... –

関連する問題