Author: david
Date: Mon Feb 14 14:14:49 2011
New Revision: 8976
Log:
Generate missing slugs
Added:
trunk/lib/task/propelGenerateSlugsTask.class.php (contents, props changed)
Modified:
trunk/lib/model/QubitObject.php
Modified: trunk/lib/model/QubitObject.php
==============================================================================
--- trunk/lib/model/QubitObject.php Mon Feb 14 13:04:17 2011 (r8975)
+++ trunk/lib/model/QubitObject.php Mon Feb 14 14:14:49 2011 (r8976)
@@ -208,6 +208,11 @@
public function insertSlug($connection)
{
+ if (!isset($connection))
+ {
+ $connection =
QubitTransactionFilter::getConnection(QubitObject::DATABASE_NAME);
+ }
+
if (isset($this->slug))
{
$statement = $connection->prepare('
Added: trunk/lib/task/propelGenerateSlugsTask.class.php
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/lib/task/propelGenerateSlugsTask.class.php Mon Feb 14 14:14:49
2011 (r8976)
@@ -0,0 +1,82 @@
+<?php
+
+/*
+ * This file is part of Qubit Toolkit.
+ *
+ * Qubit Toolkit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Qubit Toolkit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qubit Toolkit. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * Regenerate nested set column values
+ *
+ * @package symfony
+ * @subpackage task
+ * @author David Juhasz <[email protected]>
+ * @version SVN: $Id$
+ */
+class propelBuildNestedSetTask extends sfBaseTask
+{
+ /**
+ * @see sfTask
+ */
+ protected function configure()
+ {
+ $this->addArguments(array(
+ ));
+
+ $this->addOptions(array(
+ new sfCommandOption('application', null,
sfCommandOption::PARAMETER_OPTIONAL, 'The application name', true),
+ new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED,
'The environment', 'cli'),
+ new sfCommandOption('connection', null,
sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'),
+ ));
+
+ $this->namespace = 'propel';
+ $this->name = 'generateSlugs';
+ $this->briefDescription = 'Generate slugs for all slug-less objects.';
+
+ $this->detailedDescription = <<<EOF
+Generate slugs for all slug-less objects.
+EOF;
+ }
+
+ /**
+ * @see sfTask
+ */
+ public function execute($arguments = array(), $options = array())
+ {
+ $this->logSection('propel', 'Generate missing slugs...');
+
+ $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';
+
+ $databaseManager = new sfDatabaseManager($this->configuration);
+
+ $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);
+ }
+
+ $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.