Changeset 785503
- Timestamp:
- 10/09/2013 07:25:43 PM (12 years ago)
- File:
-
- 1 edited
-
observer/trunk/lib/AMWObserver.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
observer/trunk/lib/AMWObserver.php
r782634 r785503 4 4 5 5 protected $logfile; 6 protected $version = '1.0. 2';6 protected $version = '1.0.3'; 7 7 8 8 /** … … 94 94 // ignore transients 95 95 if (preg_match('/.*_transient_.*/i', $option)) return; 96 // convert values to strings 97 $oldvalue = (is_array($oldvalue) || is_object($oldvalue)) ? serialize($oldvalue) : $oldvalue; 98 $newvalue = (is_array($newvalue) || is_object($newvalue)) ? serialize($newvalue) : $newvalue; 99 $data = sprintf("(%s)->(%s)", $oldvalue, $newvalue); 100 $site = get_current_site(); 101 $this->log('update_site_option', $site->id, $option, $data); 96 97 // handle this option separately? 98 $optionsWithArrayValues = array( 99 'site_admins', 100 'active_sitewide_plugins', 101 ); 102 103 // log 104 //if (in_array($option, $optionsWithArrayValues)) { 105 if (is_array($oldvalue) || is_array($newvalue)) { 106 107 $this->handle_option_arrays('update_site_option', $option, $oldvalue, $newvalue); 108 109 } else { 110 111 // convert values to strings 112 $oldvalue = (is_array($oldvalue) || is_object($oldvalue)) ? serialize($oldvalue) : $oldvalue; 113 $newvalue = (is_array($newvalue) || is_object($newvalue)) ? serialize($newvalue) : $newvalue; 114 $data = sprintf("(%s)->(%s)", $oldvalue, $newvalue); 115 $site = get_current_site(); 116 $this->log('update_site_option', $site->id, $option, $data); 117 118 } 102 119 } 103 120 … … 123 140 124 141 // handle this option separately? 125 $specialHandler = 'handle_option_' . $option; 126 if (method_exists($this, $specialHandler)) { 127 128 call_user_func(array(&$this, $specialHandler), $option, $oldvalue, $newvalue); 142 $optionsWithArrayValues = array( 143 'recently_edited', 144 ); 145 146 //if (in_array($option, $optionsWithArrayValues)) { 147 if (is_array($oldvalue) || is_array($newvalue)) { 148 149 $this->handle_option_arrays('updated_option', $option, $oldvalue, $newvalue); 129 150 130 151 } else { … … 142 163 143 164 /** 144 * Logs when 'active_plugins' option is updated. 165 * Logs the difference in options that store serialized arrays. 166 * Makes the differences easier to spot and read. 167 * 168 * @param string $action The triggered action. 145 169 * @param string $option The name of the option that was changed. 146 170 * @param mixed $newvalue The new value for the option. … … 148 172 * @return void 149 173 */ 150 public function handle_option_a ctive_plugins($option, $oldvalue, $newvalue) {174 public function handle_option_arrays($action, $option, $oldvalue, $newvalue) { 151 175 152 176 // make sure we work with arrays … … 155 179 156 180 // get changes 157 $deactivated = array_diff($oldvalue, $newvalue); 158 $activated = array_diff($newvalue, $oldvalue); 181 if ($this->is_assoc($oldvalue) || $this->is_assoc($newvalue)) { 182 $deactivated = array_diff_assoc($oldvalue, $newvalue); 183 $activated = array_diff_assoc($newvalue, $oldvalue); 184 } else { 185 $deactivated = array_diff($oldvalue, $newvalue); 186 $activated = array_diff($newvalue, $oldvalue); 187 } 159 188 160 189 // make a readable representation of the changes 161 190 $data = ''; 162 191 if (count($deactivated)) { 163 $data .= '(DEACTIVATED: "' . implode('","', $deactivated) . '")'; 192 $withKeys = array(); 193 foreach ($deactivated as $k=>$v) { 194 $withKeys[] = $k.' => '.$v; 195 } 196 $deactivatedStr = '"' . implode('","', $withKeys) . '"'; 197 $data .= '(removed: '.$deactivatedStr.')'; 164 198 } 165 199 if (count($activated)) { 166 $data .= '(ACTIVATED: "' . implode('","', $activated) . '")'; 200 $withKeys = array(); 201 foreach ($activated as $k=>$v) { 202 $withKeys[] = $k.' => '.$v; 203 } 204 $activatedStr = '"' . implode('","', $withKeys) . '"'; 205 $data .= '(added: '.$activatedStr.')'; 167 206 } 168 207 169 208 // log it 170 209 $blogId = get_current_blog_id(); 171 $this->log('updated_option', $blogId, $option, $data); 172 210 $this->log($action, $blogId, $option, $data); 211 212 } 213 214 /** 215 * Returns true if the given array is associative. 216 * @param array $array The array to check. 217 * @return boolean 218 */ 219 private function is_assoc($array) { 220 return (bool)count(array_filter(array_keys($array), 'is_string')); 173 221 } 174 222
Note: See TracChangeset
for help on using the changeset viewer.