Author: jablko
Date: Mon Nov 1 20:40:27 2010
New Revision: 8756
Log:
Check @href is one of our resources, fixes issue 1869
Modified:
trunk/lib/Qubit.class.php
trunk/plugins/sfEacPlugin/lib/sfEacPlugin.class.php
Modified: trunk/lib/Qubit.class.php
==============================================================================
--- trunk/lib/Qubit.class.php Mon Nov 1 15:29:22 2010 (r8755)
+++ trunk/lib/Qubit.class.php Mon Nov 1 20:40:27 2010 (r8756)
@@ -26,7 +26,7 @@
// goal is to get path info from valid URL, which the following simple
// regex should accomplish. Slash characters don't occur in the scheme,
// user, password, host, or port component of valid URL
- return
preg_replace('/^(http:\/\/|https\:\/\/)?[^\/]*'.preg_quote(sfContext::getInstance()->request->getPathInfoPrefix(),
'/').'/', null, $url);
+ return
preg_replace('/^(?:[^:]+:\/\/[^\/]+)?'.preg_quote(sfContext::getInstance()->request->getPathInfoPrefix(),
'/').'/', null, $url);
}
// Alternative to format_date() symfony helper
Modified: trunk/plugins/sfEacPlugin/lib/sfEacPlugin.class.php
==============================================================================
--- trunk/plugins/sfEacPlugin/lib/sfEacPlugin.class.php Mon Nov 1 15:29:22
2010 (r8755)
+++ trunk/plugins/sfEacPlugin/lib/sfEacPlugin.class.php Mon Nov 1 20:40:27
2010 (r8756)
@@ -530,20 +530,20 @@
// <descriptiveNote/>, <placeEntry/>
foreach ($fd->find('eac:cpfDescription/eac:relations/eac:cpfRelation') as
$node)
{
- $item = new QubitActor;
- if ($node->hasAttributeNS('http://www.w3.org/1999/xlink', 'href'))
+ $url =
preg_replace('/^(?:[^:]+:\/\/[^\/]+)?'.preg_quote(sfContext::getInstance()->request->getPathInfoPrefix(),
'/').'/', null, $node->getAttributeNS('http://www.w3.org/1999/xlink', 'href'),
-1, $count);
+
+ // @href is one of our resources
+ if ($node->hasAttributeNS('http://www.w3.org/1999/xlink', 'href') && 0 <
$count)
{
- $params =
sfContext::getInstance()->routing->parse(Qubit::pathInfo($node->getAttributeNS('http://www.w3.org/1999/xlink',
'href')));
- if (isset($params['_sf_route']->resource))
- {
- $item = $params['_sf_route']->resource;
- }
+ $params = sfContext::getInstance()->routing->parse($url);
+ $item = $params['_sf_route']->resource;
}
-
- // TODO: Chain save of related actor through QubitRelation
- if (!isset($item->id))
+ else
{
+ $item = new QubitActor;
$item->authorizedFormOfName =
$fd->spawn()->add($node)->find('eac:relationEntry')->text();
+
+ // TODO Cascade save through QubitEvent
$item->save();
}
@@ -551,25 +551,24 @@
$relation->object = $item;
$relation->typeId =
self::fromCpfRelationType($node->getAttribute('cpfRelationType'));
- if (0 < count($dates = self::parseDates($node)))
+ if (0 < count($date = self::parseDates($node)))
{
- $relation->startDate = $dates[0][0];
- $relation->endDate = $dates[count($dates)-1][1];
+ $relation->startDate = $date[0][0];
+ $relation->endDate = $date[count($date) - 1][1];
}
- // Describe multiple, non-contiguous dates using date display note
- if (1 < count($dates))
+ // Multiple, non-contiguous dates
+ if (1 < count($date))
{
- $display = '';
- foreach ($dates as $range)
+ foreach ($date as $key => $value)
{
- $display .= sprintf(', %s - %s', Qubit::renderDate($range[0]),
Qubit::renderDate($range[1]));
+ $date[$key] = Qubit::renderDate($value[0]).' -
'.Qubit::renderDate($value[1]);
}
$note = new QubitNote;
$note->typeId = QubitTerm::RELATION_NOTE_DATE_ID;
$note->scope = 'QubitRelation';
- $note->content = substr($display, 2);
+ $note->content = implode(', ', $date);
$relation->notes[] = $note;
}
@@ -581,23 +580,21 @@
// <descriptiveNote/>, <placeEntry/>
foreach
($fd->find('eac:cpfDescription/eac:relations/eac:resourceRelation') as $node)
{
- $item = new QubitInformationObject;
- if ($node->hasAttributeNS('http://www.w3.org/1999/xlink', 'href'))
- {
- $params =
sfContext::getInstance()->routing->parse(Qubit::pathInfo($node->getAttributeNS('http://www.w3.org/1999/xlink',
'href')));
+ $url =
preg_replace('/^(?:[^:]+:\/\/[^\/]+)?'.preg_quote(sfContext::getInstance()->request->getPathInfoPrefix(),
'/').'/', null, $node->getAttributeNS('http://www.w3.org/1999/xlink', 'href'),
-1, $count);
- if (isset($params['id']))
- {
- $item = QubitInformationObject::getById($params['id']);
- }
+ // @href is one of our resources
+ if ($node->hasAttributeNS('http://www.w3.org/1999/xlink', 'href') && 0 <
$count)
+ {
+ $params = sfContext::getInstance()->routing->parse($url);
+ $item = $params['_sf_route']->resource;
}
-
- if (!isset($item->id))
+ else
{
+ $item = new QubitInformationObject;
$item->parentId = QubitInformationObject::ROOT_ID;
$item->title =
$fd->spawn()->add($node)->find('eac:relationEntry')->text();
- // TODO cascade save through QubitEvent
+ // TODO Cascade save through QubitEvent
$item->save();
}
@@ -605,23 +602,21 @@
$event->informationObject = $item;
$event->typeId =
self::fromResourceRelationType($node->getAttribute('resourceRelationType'));
- // Start and end date describe extremes of date range(s)
- if (0 < count($dates = self::parseDates($node)))
+ if (0 < count($date = self::parseDates($node)))
{
- $event->startDate = $dates[0][0];
- $event->endDate = $dates[count($dates)-1][1];
+ $event->startDate = $date[0][0];
+ $event->endDate = $date[count($date) - 1][1];
}
- // Describe multiple, non-contiguous dates using date
- if (1 < count($dates))
+ // Multiple, non-contiguous dates
+ if (1 < count($date))
{
- $display = '';
- foreach ($dates as $range)
+ foreach ($date as $key => $value)
{
- $display .= sprintf(', %s - %s', Qubit::renderDate($range[0]),
Qubit::renderDate($range[1]));
+ $date[$key] = Qubit::renderDate($value[0]).' -
'.Qubit::renderDate($value[1]);
}
- $event->date = substr($display, 2);
+ $event->date = implode(', ', $date);
}
$this->resource->events[] = $event;
@@ -631,12 +626,21 @@
// <placeEntry/>, @lastDateTimeVerified
foreach
($fd->find('eac:cpfDescription/eac:relations/eac:functionRelation') as $node)
{
- $item = new QubitFunction;
- $item->authorizedFormOfName =
$fd->spawn()->add($node)->find('eac:relationEntry')->text();
- if ($node->hasAttributeNS('http://www.w3.org/1999/xlink', 'href'))
+ $url =
preg_replace('/^(?:[^:]+:\/\/[^\/]+)?'.preg_quote(sfContext::getInstance()->request->getPathInfoPrefix(),
'/').'/', null, $node->getAttributeNS('http://www.w3.org/1999/xlink', 'href'),
-1, $count);
+
+ // @href is one of our resources
+ if ($node->hasAttributeNS('http://www.w3.org/1999/xlink', 'href') && 0 <
$count)
{
- $params =
sfContext::getInstance()->routing->parse(Qubit::pathInfo($node->getAttributeNS('http://www.w3.org/1999/xlink',
'href')));
- $item = QubitFunction::getById($params['id']);
+ $params = sfContext::getInstance()->routing->parse($url);
+ $item = $params['_sf_route']->resource;
+ }
+ else
+ {
+ $item = new QubitFunction;
+ $item->authorizedFormOfName =
$fd->spawn()->add($node)->find('eac:relationEntry')->text();
+
+ // TODO Cascade save through QubitEvent
+ $item->save();
}
$relation = new QubitRelation;
--
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.