Pārlūkot izejas kodu

Merge pull request #1188 from Arantor/release-2.1

Odds and ends
Arantor 10 gadi atpakaļ
vecāks
revīzija
87a7e1367c
3 mainītis faili ar 82 papildinājumiem un 19 dzēšanām
  1. 81 0
      Sources/ManagePaid.php
  2. 0 18
      Sources/Subs.php
  3. 1 1
      Sources/Themes.php

+ 81 - 0
Sources/ManagePaid.php

@@ -404,6 +404,78 @@ function ModifySubscription()
 		checkSession();
 		validateToken('admin-pmsd');
 
+		// Before we delete the subscription we need to find out if anyone currently has said subscription.
+		$request = $smcFunc['db_query']('', '
+			SELECT ls.id_member, ls.old_id_group, mem.id_group, mem.additional_groups
+			FROM {db_prefix}log_subscribed AS ls
+				INNER JOIN {db_prefix}members AS mem ON (ls.id_member = mem.id_member)
+			WHERE id_subscribe = {int:current_subscription}
+				AND status = {int:is_active}',
+			array(
+				'current_subscription' => $context['sub_id'],
+				'is_active' => 1,
+			)
+		);
+		$members = array();
+		while ($row = $smcFunc['db_fetch_assoc']($request))
+		{
+			$id_member = array_shift($row);
+			$members[$id_member] = $row;
+		}
+		$smcFunc['db_free_result']($request);
+
+		// If there are any members with this subscription, we have to do some more work before we go any further.
+		if (!empty($members))
+		{
+			$request = $smcFunc['db_query']('', '
+				SELECT id_group, add_groups
+				FROM {db_prefix}subscriptions
+				WHERE id_subscribe = {int:current_subscription}',
+				array(
+					'current_subscription' => $context['sub_id'],
+				)
+			);
+			$id_group = 0;
+			$add_groups = '';
+			if ($smcFunc['db_num_rows']($request))
+				list ($id_group, $add_groups) = $smcFunc['db_fetch_row']($request);
+			$smcFunc['db_free_result']($request);
+
+			$changes = array();
+
+			// Is their group changing? This subscription may not have changed primary group.
+			if (!empty($id_group))
+			{
+				foreach ($members as $id_member => $member_data)
+				{
+					// If their current primary group isn't what they had before the subscription, and their current group was
+					// granted by the sub, remove it.
+					if ($member_data['old_id_group'] != $member_data['id_group'] && $member_data['id_group'] == $id_group)
+						$changes[$id_member]['id_group'] = $member_data['old_id_group'];
+				}
+			}
+
+			// Did this subscription add secondary groups?
+			if (!empty($add_groups))
+			{
+				$add_groups = explode(',', $add_groups);
+				foreach ($members as $id_member => $member_data)
+				{
+					// First let's get their groups sorted.
+					$current_groups = explode(',', $member_data['additional_groups']);
+					$new_groups = implode(',', array_diff($current_groups, $add_groups));
+					if ($new_groups != $member_data['additional_groups'])
+						$changes[$id_member]['additional_groups'] = $new_groups;
+				}
+			}
+
+			// We're going through changes...
+			if (!empty($changes))
+				foreach ($changes as $id_member => $new_values)
+					updateMemberData($id_member, $new_values);
+		}
+
+		// Delete the subscription
 		$smcFunc['db_query']('delete_subscription', '
 			DELETE FROM {db_prefix}subscriptions
 			WHERE id_subscribe = {int:current_subscription}',
@@ -412,6 +484,15 @@ function ModifySubscription()
 			)
 		);
 
+		// And delete any subscriptions to it to clear the phantom data too.
+		$smcFunc['db_query']('', '
+			DELETE FROM {db_prefix}log_subscribed
+			WHERE id_subscribe = {int:current_subscription}',
+			array(
+				'current_subscription' => $context['sub_id'],
+			)
+		);
+
 		call_integration_hook('integrate_delete_subscription', array($context['sub_id']));
 
 		redirectexit('action=admin;area=paidsubscribe;view');

+ 0 - 18
Sources/Subs.php

@@ -3663,24 +3663,6 @@ function clean_cache($type = '')
 	clearstatcache();
 }
 
-/**
- * Load classes that are both (E_STRICT) PHP 4 and PHP 5 compatible.
- * - removed php4 support
- * - left shell in place for mod compatablily
- *
- * @param string $filename
- * @todo remove this function since we are no longer supporting PHP < 5
- */
-function loadClassFile($filename)
-{
-	global $sourcedir;
-
-	if (!file_exists($sourcedir . '/' . $filename))
-		fatal_lang_error('error_bad_file', 'general', array($sourcedir . '/' . $filename));
-
-	require_once($sourcedir . '/' . $filename);
-}
-
 /**
  * Sets up all of the top menu buttons
  * Saves them in the cache if it is available and on

+ 1 - 1
Sources/Themes.php

@@ -1724,7 +1724,7 @@ function EditTheme()
 			$_REQUEST['filename'] = preg_replace(array('~^[\./\\:\0\n\r]+~', '~[\\\\]~', '~/[\./]+~'), array('', '/', '/'), $_REQUEST['filename']);
 
 			$temp = realpath($currentTheme['theme_dir'] . '/' . $_REQUEST['filename']);
-			if (empty($temp) || substr($temp, 0, strlen(realpath($theme_dir))) != realpath($currentTheme['theme_dir']))
+			if (empty($temp) || substr($temp, 0, strlen(realpath($currentTheme['theme_dir']))) != realpath($currentTheme['theme_dir']))
 				$_REQUEST['filename'] = '';
 		}