Beispiel #1
0
 /**
  * Return display data for batch display screen
  *
  * @param string $type 
  * @return array
  */
 public function get_comparison_data($type)
 {
     $ret = false;
     switch ($type) {
         case 'post_types':
             if (count($this->c_data['post_types'])) {
                 foreach ($this->c_data['post_types'] as $post_type => $post_objects) {
                     $ret[$post_type] = array();
                     if (count($post_objects) && count($this->s_data['post_types'][$post_type])) {
                         foreach ($post_objects as $id => $post) {
                             if (!empty($this->s_data['post_types'][$post_type][$id])) {
                                 $post->status = $this->s_data['post_types'][$post_type][$id];
                                 $post->modified = null;
                                 $post->errors = null;
                                 $post->profile();
                                 if (empty($post->status['remote_status'])) {
                                     $post->modified[] = __('new', 'cf-deploy');
                                 } elseif (!empty($post->status['remote_status'])) {
                                     // modified time
                                     if (strtotime($post->post_modified) > strtotime($post->status['remote_status']['post_modified'])) {
                                         $post->modified[] = __('local newer', 'cf-deploy');
                                     } elseif (strtotime($post->post_modified) < strtotime($post->status['remote_status']['post_modified'])) {
                                         $post->modified[] = __('remote newer', 'cf-deploy');
                                     }
                                     // meta profile
                                     if (md5(serialize($post->profile['meta'])) != md5(serialize($post->status['remote_status']['profile']['meta']))) {
                                         $post->modified[] = __('meta', 'cf-deploy');
                                     }
                                     // attachments: we need to prune attachments a bit to get an accurate comparison. prune: post_parent, post_name
                                     $atts = array('a' => $post->profile['attachments'], 'b' => $post->status['remote_status']['profile']['attachments']);
                                     foreach ($atts as &$attachments) {
                                         if (!empty($attachments)) {
                                             foreach ($attachments as &$attachment) {
                                                 unset($attachment['post']['post_parent'], $attachment['post']['post_name']);
                                             }
                                         }
                                     }
                                     if (md5(serialize($atts['a'])) != md5(serialize($atts['b']))) {
                                         $post->modified[] = __('attachments', 'cf-deploy');
                                     }
                                     unset($atts);
                                     // taxonomies
                                     if (md5(serialize($post->profile['taxonomies'])) != md5(serialize($post->status['remote_status']['profile']['taxonomies']))) {
                                         $post->modified[] = __('taxonomies', 'cf-deploy');
                                     }
                                     // attachment content
                                     if ($post_type == 'attachment') {
                                         foreach ($post->profile['post'] as $key => $value) {
                                             if ($post->status['remote_status']['profile']['post'][$key] !== $value) {
                                                 $post->modified[] = 'local and remote differ';
                                                 break;
                                             }
                                         }
                                     }
                                 }
                                 if (!empty($post->modified) || $post->force_in_batch) {
                                     if (!empty($this->data['post_types'][$post_type]) && in_array($post->ID, $this->data['post_types'][$post_type])) {
                                         $post->selected = true;
                                     }
                                     $ret[$post_type][$id] = $post;
                                 }
                             }
                         }
                         if (!empty($this->s_data['post_types'][$post_type]['__error__'])) {
                             $ret[$post_type]['__error__'] = $this->s_data['post_types'][$post_type]['__error__'];
                         }
                     }
                 }
             }
             break;
         case 'users':
             if (count($this->c_data[$type])) {
                 cfd_tmp_dbg('c_data_users.txt', $this->c_data[$type], 'print');
                 foreach ($this->c_data[$type] as $id => $object) {
                     if (!empty($this->s_data[$type][$id])) {
                         $object->status = $this->s_data[$type][$id];
                         cfd_tmp_dbg('c_data_users_status.txt', $object->status, 'print');
                         $_u = new cfd_user(array('user_id' => $object->ID));
                         $local_profile = serialize($_u->profile());
                         cfd_tmp_dbg('local_user_profile.txt', $local_profile, 'print');
                         $object->modified = 'no';
                         if (empty($object->status['remote_status'])) {
                             $object->modified = 'new';
                         } else {
                             $registered_difference = $object->user_registered != $object->status['remote_status']['user_registered'];
                             $profile_difference = $local_profile != $object->status['remote_status']['profile'];
                             $in_batch = !empty($this->data['users']) && in_array($object->ID, $this->data['users']);
                             if (empty($object->status['remote_status']) || $registered_difference || $profile_difference || $in_batch) {
                                 $object->modified = 'profile';
                             }
                         }
                         if ($object->modified != 'no') {
                             if (!empty($this->data[$type]) && in_array($object->ID, $this->data[$type])) {
                                 $object->selected = true;
                             }
                             $ret[$id] = $object;
                         }
                     }
                 }
                 if (!empty($this->s_data[$type]['__error__'])) {
                     $ret['__error__'] = $this->s_data[$type]['__error__'];
                 }
             }
             break;
         case 'taxonomies':
             if (count($this->c_data[$type])) {
                 foreach ($this->c_data[$type] as $tax_type => $objects) {
                     if (count($objects)) {
                         foreach ($objects as $id => $object) {
                             $object->status = $this->s_data[$type][$tax_type][$id];
                             $object->modified = null;
                             if (empty($object->status['remote_status'])) {
                                 $object->modified = 'new';
                             } elseif (!empty($object->status['remote_status'])) {
                                 if ($object->name != $object->status['remote_status']['name']) {
                                     $object->modified[] = 'name';
                                 }
                                 if ($object->description != $object->status['remote_status']['description']) {
                                     $object->modified[] = 'description';
                                 }
                                 if ($object->parent != $object->status['remote_status']['parent']) {
                                     $object->modified[] = 'parent';
                                 }
                             }
                             $in_batch = !empty($this->data[$type]) && in_array($object->term_id, $this->data[$type][$tax_type]);
                             if (!empty($object->modified) || $in_batch) {
                                 if (!empty($this->data[$type][$tax_type]) && in_array($object->term_id, $this->data[$type][$tax_type])) {
                                     $object->selected = true;
                                 }
                                 $ret[$tax_type][$id] = $object;
                             }
                         }
                         if (!empty($this->s_data[$type][$tax_type]['__error__'])) {
                             $ret[$tax_type]['__error__'] = $this->s_data[$type][$tax_type]['__error__'];
                         }
                     }
                 }
             }
             break;
         case 'bookmarks':
             if (count($this->c_data[$type])) {
                 foreach ($this->c_data[$type] as $id => $object) {
                     $object->status = $this->s_data[$type][$id];
                     $status_difference = !empty($object->status['remote_status']['link_hash']) && $object->status['link_hash'] != $object->status['remote_status']['link_hash'];
                     $in_batch = !empty($this->data[$type]) && in_array($object->link_id, $this->data[$type]);
                     if (empty($object->status['remote_status']) || $status_difference || $in_batch) {
                         if (!empty($this->data[$type]) && in_array($object->link_id, $this->data[$type])) {
                             $object->selected = true;
                         }
                         $ret[$id] = $object;
                     }
                 }
                 if (!empty($this->s_data[$type]['__error__'])) {
                     $ret['__error__'] = $this->s_data[$type]['__error__'];
                 }
             }
             break;
         case 'menus':
             if (count($this->c_data[$type])) {
                 foreach ($this->c_data[$type] as $id => $object) {
                     $object->status = $this->s_data[$type][$id];
                     if (isset($object->status['remote_status'])) {
                         $modified_difference = $object->last_modified() != $object->status['remote_status']['last_modified'];
                     } else {
                         $modified_difference = true;
                     }
                     $in_batch = !empty($this->data[$type]) && in_array($object->id(), $this->data[$type]);
                     if (empty($object->status['remote_status']) || $modified_difference || $in_batch) {
                         if (!empty($this->data[$type]) && in_array($object->id(), $this->data[$type])) {
                             $object->selected = true;
                         }
                         $ret[$id] = $object;
                     }
                 }
                 if (!empty($this->s_data[$type]['__error__'])) {
                     $ret['__error__'] = $this->s_data[$type]['__error__'];
                 }
             }
             break;
         default:
             throw new Exception(__('Unknown type requested: ', 'cf-deploy') . $type);
             break;
     }
     return $ret;
 }
 protected function compare_users($data)
 {
     global $wpdb;
     $user_logins = array();
     foreach ($data as $user) {
         $user_logins[] = $wpdb->escape($user['user_login']);
     }
     $_logins = '"' . implode('", "', $user_logins) . '"';
     $query = sprintf('SELECT ID, user_login, user_email, user_registered FROM ' . $wpdb->users . ' WHERE user_login IN (%s)', $_logins);
     $_users = $wpdb->get_results($query, ARRAY_A);
     $users = array();
     foreach ($_users as $user) {
         $_u = new cfd_user(array('user_id' => $user['ID']));
         $user['profile'] = serialize($_u->profile());
         $users[$user['user_login']] = $user;
     }
     return $users;
 }