summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Palmer <nick@sluggardy.net>2007-06-20 23:17:02 +0000
committerNick Palmer <nick@sluggardy.net>2007-06-20 23:17:02 +0000
commit5a9afa5379ba9c959dabeb763c33794fa3f8e1ac (patch)
tree97e3094a827ceadeaf12a435f95e53d9a86814af
parenta0554231281af269fcbc6422c065c6a5f6936dc0 (diff)
downloadliberty-5a9afa5379ba9c959dabeb763c33794fa3f8e1ac.tar.gz
liberty-5a9afa5379ba9c959dabeb763c33794fa3f8e1ac.tar.bz2
liberty-5a9afa5379ba9c959dabeb763c33794fa3f8e1ac.zip
Add new expungingAttachment call to LibertyAttachable to notify content that an attachment it is connected to is dying. Restore delete to edit_storage_list gated by a new permission. Ensure that fisheye and treasury delete when their attachments delete.
-rw-r--r--LibertyAttachable.php35
-rw-r--r--LibertyBase.php23
-rw-r--r--admin/schema_inc.php1
-rw-r--r--edit_storage_inc.php4
-rw-r--r--templates/edit_storage_list.tpl4
5 files changed, 58 insertions, 9 deletions
diff --git a/LibertyAttachable.php b/LibertyAttachable.php
index 9bd3ddf..db7e72e 100644
--- a/LibertyAttachable.php
+++ b/LibertyAttachable.php
@@ -3,7 +3,7 @@
* Management of Liberty Content
*
* @package liberty
- * @version $Header: /cvsroot/bitweaver/_bit_liberty/LibertyAttachable.php,v 1.106 2007/06/18 21:53:55 nickpalmer Exp $
+ * @version $Header: /cvsroot/bitweaver/_bit_liberty/LibertyAttachable.php,v 1.107 2007/06/20 23:17:01 nickpalmer Exp $
* @author spider <spider@steelsun.com>
*/
// +----------------------------------------------------------------------+
@@ -520,8 +520,13 @@ class LibertyAttachable extends LibertyContent {
if( $guid && ($user_id == $gBitUser->mUserId || $gBitUser->isAdmin()) ) {
$expungeFunc = $gLibertySystem->getPluginFunction($guid,'expunge_function');
if ( $expungeFunc ) {
- // Todo: inform content we are deleting one of its attachments here.
if( $expungeFunc( $pAttachmentId ) ) {
+ // Find all the content that will care.
+ $sql = "SELECT lc.`content_type_guid`, lc.`content_id` FROM `".BIT_DB_PREFIX."liberty_content` lc ".
+ "LEFT JOIN `".BIT_DB_PREFIX."liberty_attachments_map` lam on (lc.`content_id`=lam.`content_id`) ".
+ "WHERE lc.`primary_attachment_id`=? OR lam.`attachment_id`=? ORDER BY `content_type_guid`";
+ $ret = $this->mDb->getArray( $sql, array($pAttachmentId, $pAttachmentId), TRUE);
+
// Remove the primary ID from any content if it is this attachment
$sql = "UPDATE `".BIT_DB_PREFIX."liberty_content` SET `primary_attachment_id`=NULL WHERE `primary_attachment_id` = ?";
$this->mDb->query( $sql, array( $pAttachmentId ) );
@@ -533,6 +538,20 @@ class LibertyAttachable extends LibertyContent {
$this->mDb->query( $sql, array( $pAttachmentId ) );
unset($this->mStorage[$pAttachmentId]);
+
+ // Inform all the content that will care.
+ if (!empty($ret)) {
+ // Collect by content_type_guid into a single array to cut down construction costs
+ foreach($ret as $match) {
+ $content_types[$match['content_type_guid']][] = $match['content_id'];
+ }
+ foreach ($content_types as $content_type_guid => $content_ids) {
+ // expungingAttachment is a class oriented method not an object oriented method
+ // in order to save loading objects that may not care.
+ $cls = $this->getLibertyClass($content_type_guid);
+ $cls->expungingAttachment($pAttachmentId, $content_ids);
+ }
+ }
}
} else {
print("Expunge function not found for this content!");
@@ -545,6 +564,18 @@ class LibertyAttachable extends LibertyContent {
}
/**
+ * Called during attachment deletion to notify a content type that an attachment for content of that type is going away so
+ * it can take appropriate action. Note that it is VITAL that content NOT call expunge(TRUE) as part of handling this
+ * notification or else the universe will implode.
+ *
+ * @param the id of the attachment being deleted
+ * @param an array of content_ids that reference this attachment that are of this type.
+ */
+ function expungingAttachment($pAttachmentId, $pContentIds) {
+ // The default is to ignore this notification.
+ }
+
+ /**
* detach attachment from content
*
* @param array $pAttachmentId Attachment id that needs to be detached from the content loaded
diff --git a/LibertyBase.php b/LibertyBase.php
index 62f5128..cc0db7f 100644
--- a/LibertyBase.php
+++ b/LibertyBase.php
@@ -3,7 +3,7 @@
* Base class for Management of Liberty Content
*
* @package liberty
- * @version $Header: /cvsroot/bitweaver/_bit_liberty/LibertyBase.php,v 1.15 2007/03/14 14:02:45 spiderr Exp $
+ * @version $Header: /cvsroot/bitweaver/_bit_liberty/LibertyBase.php,v 1.16 2007/06/20 23:17:01 nickpalmer Exp $
* @author spider <spider@steelsun.com>
*/
// +----------------------------------------------------------------------+
@@ -60,14 +60,29 @@ class LibertyBase extends BitBase {
return parent::prepGetList( $pListHash );
}
+
+ /**
+ * given a content_type_guid this will return an object of the proper type
+ *
+ * @param the content type to be loaded
+ */
+ function getLibertyClass($pContentGuid) {
+ // We can abuse getLibertyObject to do the work
+ $ret = $this->getLibertyObject('1', $pContentGuid, FALSE);
+ // Make sure we don't have a content_id set though.
+ unset($ret->mContentId);
+ return $ret;
+ }
+
/**
* Given a content_id, this will return and object of the proper type
*
* @param integer content_id of the object to be returned
* @param string optional content_type_guid of pConId. This will save a select if you happen to have this info. If not, this method will look it up for you.
+ * @param call load on the content. Defaults to true.
* @returns object of the appropriate content type class
*/
- function getLibertyObject( $pContentId, $pContentGuid=NULL ) {
+ function getLibertyObject( $pContentId, $pContentGuid=NULL, $pLoadContent = TRUE ) {
$ret = NULL;
global $gLibertySystem, $gBitUser, $gBitSystem;
@@ -83,7 +98,9 @@ class LibertyBase extends BitBase {
if( defined( strtoupper( $type['handler_package'] ).'_PKG_PATH' ) ) {
require_once( constant( strtoupper( $type['handler_package'] ).'_PKG_PATH' ).$type['handler_file'] );
$ret = new $type['handler_class']( NULL, $pContentId );
- $ret->load();
+ if ($pLoadContent) {
+ $ret->load();
+ }
}
}
diff --git a/admin/schema_inc.php b/admin/schema_inc.php
index 1581f22..baad646 100644
--- a/admin/schema_inc.php
+++ b/admin/schema_inc.php
@@ -307,6 +307,7 @@ $gBitInstaller->registerUserPermissions( LIBERTY_PKG_NAME, array(
array('p_liberty_edit_comments', 'Can edit all comments', 'editors', LIBERTY_PKG_NAME),
array('p_liberty_attach_attachments', 'Can create content attachments', 'registered', LIBERTY_PKG_NAME),
array('p_liberty_detach_attachment', 'Can detach content attachments', 'registered', LIBERTY_PKG_NAME),
+ array('p_liberty_delete_attachment', 'Can delete content attachments', 'registered', LIBERTY_PKG_NAME),
array('p_liberty_print', 'Can print content', 'basic', LIBERTY_PKG_NAME),
array('p_liberty_enter_html', 'Can enter HTML', 'registered', LIBERTY_PKG_NAME),
array('p_liberty_edit_content_status', 'Can edit the status of content', 'registered', LIBERTY_PKG_NAME),
diff --git a/edit_storage_inc.php b/edit_storage_inc.php
index fa3bb1b..5bf934b 100644
--- a/edit_storage_inc.php
+++ b/edit_storage_inc.php
@@ -3,7 +3,7 @@
* edit_storage_inc
*
* @author spider <spider@steelsun.com>
- * @version $Revision: 1.13 $
+ * @version $Revision: 1.14 $
* @package liberty
* @subpackage functions
*
@@ -38,7 +38,7 @@ if( !empty( $_REQUEST['deleteAttachment'] ) ) {
$attachmentInfo = $gContent->getAttachment( $attachmentId );
// TODO: Should we have a permission for deleting attachments?
- if( $gBitUser->isAdmin() || $attachmentInfo['user_id'] == $gBitUser->mUserId ) {
+ if( $gBitUser->isAdmin() || ($attachmentInfo['user_id'] == $gBitUser->mUserId && $gBitUser->hasPermission('p_liberty_delete_attachment')) ) {
$gContent->expungeAttachment( $attachmentId );
}
} elseif( !empty( $_REQUEST['detachAttachment'] ) ) {
diff --git a/templates/edit_storage_list.tpl b/templates/edit_storage_list.tpl
index 682b945..357d808 100644
--- a/templates/edit_storage_list.tpl
+++ b/templates/edit_storage_list.tpl
@@ -37,7 +37,7 @@
<a href="{$attachmentActionBaseURL}&amp;content_id={$gContent->mContentId}&amp;detachAttachment={$attachmentId}">{biticon ipackage=icons iname="edit-cut" iexplain="detach"}</a>
{/if}
{/if}
- {*if ( $gBitUser->isAdmin() || $storage.user_id == $gBitUser->mUserId ) && !isset($storage.content_id) }
+ {if $gBitUser->isAdmin() || ($storage.user_id == $gBitUser->mUserId && $gBitUser->hasPermission('p_liberty_delete_attachments') ) }
{if $attachmentBrowser}
<a href="javascript:ajax_updater('attbrowser', '{$attachmentActionBaseURL}', 'deleteAttachment={$attachmentId}');">{biticon ipackage="icons" iname="edit-delete" iexplain="delete"}</a>
{elseif $libertyUploader || $gBitSystem->getConfig('liberty_attachment_style') == 'ajax'}
@@ -45,7 +45,7 @@
{else}
<a href="{$attachmentActionBaseURL}&amp;deleteAttachment={$attachmentId}">{biticon ipackage="icons" iname="edit-delete" iexplain="delete"}</a>
{/if}
- {/if*}
+ {/if}
</td>
<td style="text-align:center; width:30%">
{$storage.wiki_plugin_link}