add event on models to index in solr
authorclebeaupin
Mon, 29 Mar 2010 12:14:56 +0200
changeset 28 7de8d597588b
parent 26 4427c90bd892
child 35 312d961c90c0
add event on models to index in solr
web/thdProject/apps/frontend/modules/test/actions/actions.class.php
web/thdProject/config/ProjectConfiguration.class.php
web/thdProject/lib/model/doctrine/ThdDoctrineListener.class.php
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/web/thdProject/apps/frontend/modules/test/actions/actions.class.php	Mon Mar 29 12:14:56 2010 +0200
@@ -0,0 +1,19 @@
+<?php
+
+class testActions extends sfActions {
+
+  public function executeDoctrine(sfWebRequest $request) {
+	  $film = new ThdFilm();
+	  $film->setRef('012056');
+	  $film->setTitle('Film test');
+	  $film->setPitch('Pitch test');
+	  $film->setDuration(8592);
+	  $film->setDirectors('');
+	  $film->setActors('');
+	  $film->setSlugUrl('');
+	  $film->setOriginalTitle('Original title');
+	  $film->setProductionCountries('');
+	  $film->setProductionYear(5859);
+	  $film->save();
+  }
+}
--- a/web/thdProject/config/ProjectConfiguration.class.php	Wed Mar 24 19:04:36 2010 +0100
+++ b/web/thdProject/config/ProjectConfiguration.class.php	Mon Mar 29 12:14:56 2010 +0200
@@ -16,4 +16,8 @@
 	{
 	  	$this->enableAllPluginsExcept(array('sfPropelPlugin', 'sfCompat10Plugin'));
 	}
+
+  public function configureDoctrineConnection(Doctrine_Connection $conn) {
+    $conn->addRecordListener(new ThdDoctrineListener());
+  }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/web/thdProject/lib/model/doctrine/ThdDoctrineListener.class.php	Mon Mar 29 12:14:56 2010 +0200
@@ -0,0 +1,18 @@
+<?php
+
+class ThdDoctrineListener extends Doctrine_Record_Listener {
+
+  public function postInsert(Doctrine_Event $event) {
+    $obj = $event->getInvoker();
+
+    // Index in solr
+    sfContext::getInstance()->getLogger()->info("Insert object. Index in solr");
+  }
+
+  public function postUpdate(Doctrine_Event $event) {
+    $obj = $event->getInvoker();
+
+    // Reindex in solr
+    sfContext::getInstance()->getLogger()->info("Update object. Reindex in solr");
+  }
+}
\ No newline at end of file