Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: (PATCH) Warn Admin before Deleting Category  (Read 2684 times)

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
(PATCH) Warn Admin before Deleting Category
« on: July 20, 2008, 02:36:08 AM »

This patch - Admin Warning - will show a warning panel when the Admin goes to delete a Category when it still has content in it. It warns the Admin to go back and either re-locate or delete the content before deleting the Category.

This patch applies to all versions and variants of sNews 1.6.
This patch has been applied in the download available from the download page.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
(PATCH 2) Mark content as "Uncategorized when deleting Categories
« Reply #1 on: July 23, 2008, 07:30:08 PM »

The above Patch has now been replaced by a new set of patches that now eliminate "worry" for the Admin. Now... when the Admin deletes a Category... there is no warning message advising the Admin to go back and re-locate or delete the Category's associated content before deleting the Category. Now...

1 - When the Admin deletes a Category, all of its articles are given a new "published" status of "3".
2 - When the Admin goes to the "Articles > View" panel, the articles are marked with - (Status: Unpublished).
3 - The Admin can then click the "Edit" button beside an article title and re-locate the article to another category.

This new "Patch 2" has been applied in the current Official sNews16 Download (updated July 23.08)

Applying the Patches Manually
For those who have applied several mods to their snews.php file and want to apply the Patches manually.
NOTE: DO NOT copy the PHP tags above and below each block of script - they are only there to color the code as shown.

REVISION NOTE: - Revisions were applied at 8:50 p.m. (GMT) July 25.08... additional changes used with SubCategories Mods.

A - FOR CATEGORIES ONLY

Step 1: Search for #categories within the language variable array and add the following under it:
Code: [Select]
<?php

# "Uncategorized" (orphaned) links, Patch/fix July 23.08
$l['uncategorized'] = '<span style="color: #9c0000;">Uncategorized</span>';

?>


Step 2: Search for // ARTICLES - POSTING TIME and paste this new function above it:
Code: [Select]
<?php

// DELETE CATEGORY BY ID - # JULY 19.08 - Patch/fix - new function, CATEGORIES ONLY (adapted from 1.7RC)
function delete_cat($id){
$catdata mysql_fetch_array(mysql_query("SELECT catorder FROM ".db('prefix')."categories WHERE id = $id"));
$cat_order $catdata['catorder'];
mysql_query("DELETE FROM ".db('prefix')."categories WHERE id = $id LIMIT 1;");
# "Uncategorized" Patch/fix - 1 string: sets published status of deleted Cat's articles to 3 (July 23.08)
mysql_query("UPDATE ".db('prefix')."articles SET published=3 WHERE category= $id");
$query mysql_query("SELECT id,catorder FROM ".db('prefix')."categories WHERE catorder > $cat_order");
while ($r mysql_fetch_array($query)) {
mysql_query("UPDATE ".db('prefix')."categories SET catorder = catorder - 1 WHERE id = '$r[id]'");
}
}

?>



B - FOR USE WITH SUB-CATEGORIES MODS

Step 1: Search for #categories within the language variable array and add the following under it:
Code: [Select]
<?php

# "Uncategorized" (orphaned) links mod July 22.08
$l['orphan'] = '<span style="color: #9c0000;">Uncategorized</span>';
$l['uncategorized1'] = 'Un-categorized Content:';
$l['uncategorized2'] = 'The content listed below once belonged to a category that you recently deleted.<br />Click "Edit" for any content title to re-locate it now.<br />';
$l['uncategorized3'] = 'Un-categorized Sub-Cats:';
$l['uncategorized4'] = 'The Sub-category titles listed below once belonged to a Category that you recently deleted.<br />Click "Edit" for any Title to re-locate it now.<br />';

?>


Step 2: Search for // ARTICLES - POSTING TIME and paste this new function above it:
The second mysql_query string changes a Subcategory's subcat value (in categories table) to -2.
Code: [Select]
<?php

// DELETE CATEGORY BY ID - # JULY 19.08 - Patch/fix - new function, WITH SUBCATEGORIES MODS (adapted from 1.7RC)
function delete_cat($id){
$catdata mysql_fetch_array(mysql_query("SELECT catorder,subcat FROM ".db('prefix')."categories WHERE id = $id"));
$cat_order $catdata['catorder'];
$cat_subcat $catdata['subcat'];
mysql_query("DELETE FROM ".db('prefix')."categories WHERE id = $id LIMIT 1;");
# Uncategorized - 1 string: set subcat value of orphaned SubCats to -2 (keys, July 25.08)
mysql_query("UPDATE ".db('prefix')."categories SET subcat = -2 WHERE subcat = $id"); // NEW
# "Uncategorized" - 1 string: sets published status of deleted Cat's articles to 3 (Joost, July 22.08)
mysql_query("UPDATE ".db('prefix')."articles SET published=3 WHERE category= $id");
$query mysql_query("SELECT id,catorder FROM ".db('prefix')."categories WHERE catorder > $cat_order AND subcat = $cat_subcat");
while ($r mysql_fetch_array($query)) {
mysql_query("UPDATE ".db('prefix')."categories SET catorder = catorder - 1 WHERE id = '$r[id]'");
}
}

?>


Step 3: Search for function admin_categories() and... right under it, paste in this section to list Uncategorized SubCats in Categories View Panel:
Code: [Select]
<?php

#======= "Uncategorized" (orphaned) SubCat links mod July 25.08 ==============
   # Lists "Uncategorized" Subcats here by selecting & showing SubCats with subcat value "-2"
$query "SELECT * FROM ".db('prefix')."categories WHERE subcat = '-2'";
$result mysql_query($query);
if (!$result || !mysql_num_rows($result)) {echo ''; } else {
echo '<fieldset><legend>'.l('uncategorized3').'</legend>'.l('uncategorized4').'';
while($r mysql_fetch_array($result)){
   if ($r['subcat'] == -2) {
   echo '<p class="subcattitle">-&nbsp;<strong>'.$r['name'].'</strong> ('.get_identity($r['author_id'], 'username_real').') <a href="'.db('website').'index.php?action=admin_category&amp;id='.$r['id'].'" title="'.$r['description'].'">&nbsp;.&nbsp;'.l('edit').'</a> ';
      echo  l('divider').' ['.l('status').' '.l('orphan').']';
      echo '</p>';
   }
}
echo '</fieldset><br />';
}

?>


FINAL STEPS (Both A & B)

Search for if ($r['published'] == 2) and paste this just above it:
Code: [Select]
<?php

# "Uncategorized" (orphaned) links Patch/fix July 23.08 - 1 string added
if ($r['published'] == 3) {echo  l('divider').' ['.l('status').' '.l('uncategorized').']';}

?>


Search for case(isset($_POST['delete_category'])): and replace the query strings under it with the new function name:
Code: [Select]
<?php

case(isset($_POST['delete_category'])):
# "Uncategorized" Patch/fix July 23.08 - default query string replaced by function delete_cat($id);
//mysql_query("DELETE FROM ".db('prefix')."categories WHERE id = $id LIMIT 1;");
delete_cat($id);
break;

?>

« Last Edit: July 25, 2008, 08:50:49 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU