Fix publish-url property & getPublishStatus() fct

This commit is contained in:
Thomas Citharel 2016-07-06 15:09:27 +02:00 committed by Lukas Reschke
parent 981c38f6d9
commit 1652a74feb
No known key found for this signature in database
GPG Key ID: B9F6980CF6E759B1
3 changed files with 18 additions and 16 deletions

View File

@ -1501,13 +1501,16 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
*/
public function getPublishStatus($calendar) {
$query = $this->db->getQueryBuilder();
$result = $query->select(['principaluri', 'access'])
$result = $query->select('count(id)')
->from('dav_shares')
->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId())))
->andWhere($query->expr()->eq('type', $query->createNamedParameter(self::CLASSIFICATION_PUBLIC)))
->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC)))
->execute();
return count($result->fetch()) > 0;
$row = $result->fetch();
$result->closeCursor();
return $row;
}
/**

View File

@ -72,19 +72,18 @@ class PublishPlugin extends ServerPlugin
public function propFind(PropFind $propFind, INode $node)
{
if ($node instanceof Calendar) {
$token = md5(\OC::$server->getConfig()->getSystemValue('secret', '').$node->getName());
$token = md5(\OC::$server->getConfig()->getSystemValue('secret', '').$node->getName());
$publishUrl = $this->server->getBaseUri() . 'public-calendars/' . $token;
$propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node, $token) {
if ($node->getPublishStatus()) {
return new Publisher($token, $node->getPublishStatus());
}
});
$propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node, $publishUrl) {
if ($node->getPublishStatus()) {
return new Publisher($publishUrl, $node->getPublishStatus());
}
});
$propFind->handle('{'.self::NS_CALENDARSERVER.'}pre-publish-url', function () use ($node, $token) {
if ($node->getPublishStatus()) {
return new Publisher($token, false);
}
});
$propFind->handle('{'.self::NS_CALENDARSERVER.'}pre-publish-url', function () use ($node, $publishUrl) {
return new Publisher($publishUrl, false);
});
}
}

View File

@ -57,9 +57,9 @@ class Publisher implements XmlSerializable {
$cs = '{' . Plugin::NS_CALENDARSERVER . '}';
if (!$this->isPublished) {
$writer->write($this->publishUrl);
$writer->write($this->publishUrl); // for pre-publish-url
} else {
$writer->writeElement('{DAV:}href', $this->publishUrl);
$writer->writeElement('{DAV:}href', $this->publishUrl); // for publish-url
}
}