Author: david
Date: Fri Feb 25 16:58:03 2011
New Revision: 9001
Log:
Reduce code duplication with by looping through tables
Modified:
trunk/lib/task/propelGenerateSlugsTask.class.php
Modified: trunk/lib/task/propelGenerateSlugsTask.class.php
==============================================================================
--- trunk/lib/task/propelGenerateSlugsTask.class.php Fri Feb 25 16:44:03
2011 (r9000)
+++ trunk/lib/task/propelGenerateSlugsTask.class.php Fri Feb 25 16:58:03
2011 (r9001)
@@ -58,42 +58,40 @@
$databaseManager = new sfDatabaseManager($this->configuration);
$conn = $databaseManager->getDatabase('propel')->getConnection();
- $this->logSection('propel', 'Generate information object slugs...');
+ $tables = array(
+ 'actor' => 'QubitActor',
+ 'information_object' => 'QubitInformationObject'
+ );
- $sql = 'SELECT io.id, i18n.title';
- $sql .= ' FROM '.QubitInformationObject::TABLE_NAME.' io';
- $sql .= ' INNER JOIN '.QubitInformationObjectI18n::TABLE_NAME.' i18n';
- $sql .= ' ON io.id = i18n.id';
- $sql .= ' LEFT JOIN '.QubitSlug::TABLE_NAME.' sl';
- $sql .= ' ON io.id = sl.object_id';
- $sql .= ' WHERE io.source_culture = i18n.culture';
- $sql .= ' AND sl.id is NULL';
-
- foreach($conn->query($sql, PDO::FETCH_NUM) as $row)
+ foreach ($tables as $table => $classname)
{
- $obj = QubitObject::getById($row[0]);
- $obj->slug = QubitSlug::slugify($row[1]);
- $obj->insertSlug($conn);
- }
-
- $this->logSection('propel', 'Generate actor slugs...');
-
- $sql = 'SELECT base.id, i18n.authorized_form_of_name';
- $sql .= ' FROM '.QubitActor::TABLE_NAME.' base';
- $sql .= ' INNER JOIN '.QubitActorI18n::TABLE_NAME.' i18n';
- $sql .= ' ON base.id = i18n.id';
- $sql .= ' LEFT JOIN '.QubitSlug::TABLE_NAME.' sl';
- $sql .= ' ON base.id = sl.object_id';
- $sql .= ' WHERE base.source_culture = i18n.culture';
- $sql .= ' AND sl.id is NULL';
+ $this->logSection('propel', "Generate $table slugs...");
- $conn = $databaseManager->getDatabase('propel')->getConnection();
-
- foreach($conn->query($sql, PDO::FETCH_NUM) as $row)
- {
- $obj = QubitObject::getById($row[0]);
- $obj->slug = QubitSlug::slugify($row[1]);
- $obj->insertSlug($conn);
+ switch ($table)
+ {
+ case 'actor':
+ $sql = 'SELECT base.id, i18n.authorized_form_of_name';
+ break;
+
+ case 'information_object':
+ $sql = 'SELECT base.id, i18n.title';
+ break;
+ }
+
+ $sql .= ' FROM '.constant($classname.'::TABLE_NAME').' base';
+ $sql .= ' INNER JOIN '.constant($classname.'I18n::TABLE_NAME').' i18n';
+ $sql .= ' ON base.id = i18n.id';
+ $sql .= ' LEFT JOIN '.QubitSlug::TABLE_NAME.' sl';
+ $sql .= ' ON base.id = sl.object_id';
+ $sql .= ' WHERE base.source_culture = i18n.culture';
+ $sql .= ' AND sl.id is NULL';
+
+ foreach($conn->query($sql, PDO::FETCH_NUM) as $row)
+ {
+ $obj = QubitObject::getById($row[0]);
+ $obj->slug = QubitSlug::slugify($row[1]);
+ $obj->insertSlug($conn);
+ }
}
$this->logSection('propel', 'Done!');
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.