This time for real...
authorCameron Ball <c.ball1729@gmail.com>
Sat, 21 Feb 2015 08:51:19 +0000 (16:51 +0800)
committerCameron Ball <c.ball1729@gmail.com>
Sat, 21 Feb 2015 08:51:19 +0000 (16:51 +0800)
Services/CacheUpdater.php

index a913df3..e40709f 100644 (file)
@@ -4,18 +4,25 @@ namespace Services;
 \r
 use Services\ICacheUpdater;\r
 use Domain\Entities\StepMania\IPack;\r
+use DataAccess\StepMania\IPackRepository;\r
 use Domain\Util;\r
 \r
 class CacheUpdater implements ICacheUpdater\r
 {\r
     private $_json;\r
+    private $_packRepository;\r
     \r
-    public function __construct() {\r
+    public function __construct(IPackRepository $packRepository) {\r
         $this->_json = json_decode(file_get_contents('../SimfileCache/simfiles.json'), true);\r
+        $this->_packRepository = $packRepository;\r
     }\r
     \r
     public function insert(IPack $pack)\r
     {\r
+        //XXX: Tricky, when the pack comes in it may not be fully populated\r
+        //we are interested in keeping the cache in sync with the DB, so\r
+        //reload it from the DB to ensure we have everything.\r
+        $pack = $this->_packRepository->findById($pack->getId());\r
         $this->_json['packs'][] = Util::packToArray($pack);\r
         return $this;\r
     }\r