Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
Introduction of the urltitle field for shorturls. Refs #9
Browse files Browse the repository at this point in the history
  • Loading branch information
matheo committed Dec 20, 2011
1 parent 60305e5 commit 515bd2b
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 12 deletions.
6 changes: 1 addition & 5 deletions src/modules/Clip/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
$modinfo = ModUtil::getInfoFromName('Clip');

if ($modinfo['state'] == ModUtil::STATE_ACTIVE) {
// add the dynamic models path
ZLoader::addAutoloader('ClipModels', realpath(StringUtil::left(ModUtil::getVar('Clip', 'modelspath'), -11)));

// check if the models are already created
Clip_Generator::checkModels();
Clip_Util::boot();
}

if (FormUtil::getPassedValue('type') == 'admin') {
Expand Down
1 change: 1 addition & 0 deletions src/modules/Clip/lib/Clip/Doctrine/Pubdata.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ public function pubFields()
// reorder the fields conveniently
$reorder = array(
'core_title' => 'map',
'core_urltitle' => 'value',
'core_uniqueid' => 'map',
'core_tid' => 'map',
'core_pid' => 'value',
Expand Down
8 changes: 4 additions & 4 deletions src/modules/Clip/lib/Clip/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,14 +502,12 @@ public function assignClipValues(&\$obj)
if (is_object(\$obj)) {
\$obj->clip_state = false;
\$obj->mapValue('core_tid', $tid);
\$obj->mapValue('core_title', '');
\$obj->mapValue('core_titlefield', '$titlefield');
\$obj->mapValue('core_title', \$obj[\$obj->core_titlefield]);
\$obj->mapValue('core_uniqueid', \$obj->core_tid.'-'.\$obj->core_pid);
\$obj->mapValue('core_creator', (\$obj->core_author == UserUtil::getVar('uid')) ? true : false);
} else {
\$obj['core_tid'] = $tid;
\$obj['core_title'] = '';
\$obj['core_titlefield'] = '$titlefield';
\$obj['core_title'] = \$obj[\$obj['core_titlefield']];
\$obj['core_uniqueid'] = \$obj['core_tid'].'-'.\$obj['core_pid'];
Expand Down Expand Up @@ -735,6 +733,7 @@ public static function addtables($tid = false)
$tableColumnCore = array(
'id' => 'id',
'core_pid' => 'pid',
'core_urltitle' => 'urltitle',
'core_author' => 'author',
'core_hitcount' => 'hits',
'core_language' => 'language',
Expand All @@ -749,6 +748,7 @@ public static function addtables($tid = false)
$tableDefCore = array(
'id' => 'I4 PRIMARY AUTO',
'core_pid' => 'I4 NOTNULL',
'core_urltitle' => "C(255) NOTNULL",
'core_author' => 'I4 NOTNULL',
'core_hitcount' => 'I8 DEFAULT 0',
'core_language' => "C(10) NOTNULL", //FIXME how many chars are needed for a gettext code?
Expand Down Expand Up @@ -883,11 +883,11 @@ public static function createModels()
self::createRelationsModels();
}

public static function checkModels()
public static function checkModels($force = false)
{
static $checked;

if (!isset($checked)) {
if (!isset($checked) || $force) {
$checked = true;

$tid = Clip_Util::getPubType()->getFirst()->tid;
Expand Down
50 changes: 48 additions & 2 deletions src/modules/Clip/lib/Clip/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public function install()
*/
public function upgrade($oldversion)
{
Clip_Util::boot();

switch ($oldversion)
{
case '0.4.0':
Expand Down Expand Up @@ -149,6 +151,10 @@ public function upgrade($oldversion)
$dirs = self::createDirectories(array('models'));
$this->setVar('modelspath', $dirs['models']);
case '0.4.19':
if (!self::introduceUrltitle()) {
return false;
}
case '0.4.20':
// further upgrade handling
// * contenttype stuff
// Content_Installer::updateContentType('Clip');
Expand Down Expand Up @@ -832,8 +838,11 @@ private static function tempUpdate047()
$table = DBUtil::getLimitedTablename('clip_pubfields');
$sql[] = "UPDATE $table SET pm_fieldtype = 'C(1024)' WHERE pm_fieldplugin = 'Image' OR pm_fieldplugin = 'Upload'";

// update the pubtypes table
Clip_Generator::checkModels();
// update the pubdata models files
Clip_Generator::resetModels();
Clip_Generator::checkModels(true);

// update the database
$pubtypes = Doctrine_Core::getTable('Clip_Model_Pubtype')->selectFieldArray('tid');
foreach ($pubtypes as $tid) {
Doctrine_Core::getTable('ClipModels_Pubdata'.$tid)->changeTable();
Expand Down Expand Up @@ -1009,6 +1018,43 @@ private function upgradeDBpre09()
return true;
}

/**
* Upgrade models and databases to introduce the urltitle field.
*
* @return boolean
*/
private static function introduceUrltitle()
{
// regen models
Clip_Generator::resetModels();
Clip_Generator::checkModels(true);

// update the database
$pubtypes = Doctrine_Core::getTable('Clip_Model_Pubtype')->selectFieldArray('tid');
foreach ($pubtypes as $tid) {
//DoctrineUtil::createColumn('clip_pubdata'.$tid, 'urltitle', array('type' => 'string', 'length' => 255));

// fill the urltitles
$sql = array();

$tablename = DBUtil::getLimitedTablename('clip_pubdata'.$tid);
$titlefield = Clip_Util::getTitleField($tid);
$records = Doctrine_Core::getTable('ClipModels_Pubdata'.$tid)->selectFieldArray($titlefield, array(), '', false, 'id');

foreach ($records as $id => $title) {
$urltitle = substr(DataUtil::formatPermalink($title), 0, 255);

$sql[] = "UPDATE {$tablename} SET urltitle = '{$urltitle}' WHERE id = {$id}";
}

foreach ($sql as $q) {
if (!DBUtil::executeSQL($q)) {
return LogUtil::registerError($this->__('Error! Update attempt failed.')." - $sql");
}
}
}
}

/**
* Map old ContentType names to new.
*
Expand Down
14 changes: 14 additions & 0 deletions src/modules/Clip/lib/Clip/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ public static function setArgs($id, $args)
self::$args[$id] = $args;
}

/**
* Clip boot
*
* @return void
*/
public static function boot()
{
// add the dynamic models path
ZLoader::addAutoloader('ClipModels', realpath(StringUtil::left(ModUtil::getVar('Clip', 'modelspath'), -11)));

// check if the models are already created
Clip_Generator::checkModels();
}

/**
* Extract the TID from a string end.
*
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Clip/lib/Clip/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getMetaData()
$meta['oldnames'] = array('PageMaster');
//! module name that appears in URL
$meta['url'] = $this->__('clip');
$meta['version'] = '0.4.19';
$meta['version'] = '0.4.20';
$meta['core_min'] = '1.3.2';
$meta['core_max'] = '1.3.99';

Expand Down

0 comments on commit 515bd2b

Please sign in to comment.