Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 8 commits
  • 6 files changed
  • 0 comments
  • 2 contributors
34  classes/PodsAPI.php
@@ -789,6 +789,9 @@ public function save_pod ( $params ) {
789 789
 
790 790
         $pod[ 'options' ] = array_merge( $pod[ 'options' ], $options );
791 791
 
  792
+        if ( strlen( $pod[ 'label' ] ) < 1 )
  793
+            $pod[ 'label' ] = $pod[ 'name' ];
  794
+
792 795
         $params->id = $pod[ 'id' ];
793 796
         $params->name = $pod[ 'name' ];
794 797
 
@@ -868,7 +871,8 @@ public function save_pod ( $params ) {
868 871
                 'ID' => $pod[ 'id' ],
869 872
                 'post_name' => $pod[ 'name' ],
870 873
                 'post_title' => $pod[ 'label' ],
871  
-                'post_content' => $pod[ 'description' ]
  874
+                'post_content' => $pod[ 'description' ],
  875
+                'post_status' => 'publish'
872 876
             );
873 877
         }
874 878
 
@@ -1148,13 +1152,16 @@ public function save_field ( $params, $table_operation = true ) {
1148 1152
 
1149 1153
             foreach ( $aliases as $alias ) {
1150 1154
                 if ( isset( $options[ $alias ] ) ) {
1151  
-                    $field[ $exclude_field ] = $options[ $alias ];
  1155
+                    $field[ $exclude_field ] = trim( $options[ $alias ] );
1152 1156
 
1153 1157
                     unset( $options[ $alias ] );
1154 1158
                 }
1155 1159
             }
1156 1160
         }
1157 1161
 
  1162
+        if ( strlen( $field[ 'label' ] ) < 1 )
  1163
+            $field[ 'label' ] = $field[ 'name' ];
  1164
+
1158 1165
         $field[ 'options' ][ 'type' ] = $field[ 'type' ];
1159 1166
 
1160 1167
         if ( in_array( $field[ 'type' ], $tableless_field_types ) ) {
@@ -1166,12 +1173,12 @@ public function save_field ( $params, $table_operation = true ) {
1166 1173
                     $field[ 'pick_val' ] = pods_str_replace( 'pod-', '', $field[ 'pick_object' ], 1 );
1167 1174
                     $field[ 'pick_object' ] = 'pod';
1168 1175
                 }
1169  
-                elseif ( 0 === strpos( 'post-types-', $field[ 'pick_object' ] ) ) {
1170  
-                    $field[ 'pick_val' ] = pods_str_replace( 'post-types-', '', $field[ 'pick_object' ], 1 );
  1176
+                elseif ( 0 === strpos( 'post-type-', $field[ 'pick_object' ] ) ) {
  1177
+                    $field[ 'pick_val' ] = pods_str_replace( 'post-type-', '', $field[ 'pick_object' ], 1 );
1171 1178
                     $field[ 'pick_object' ] = 'post_type';
1172 1179
                 }
1173  
-                elseif ( 0 === strpos( 'taxonomies-', $field[ 'pick_object' ] ) ) {
1174  
-                    $field[ 'pick_val' ] = pods_str_replace( 'taxonomies-', '', $field[ 'pick_object' ], 1 );
  1180
+                elseif ( 0 === strpos( 'taxonomy-', $field[ 'pick_object' ] ) ) {
  1181
+                    $field[ 'pick_val' ] = pods_str_replace( 'taxonomy-', '', $field[ 'pick_object' ], 1 );
1175 1182
                     $field[ 'pick_object' ] = 'taxonomy';
1176 1183
                 }
1177 1184
             }
@@ -2578,9 +2585,12 @@ public function load_pod ( $params, $strict = true ) {
2578 2585
             'description' => $_pod[ 'post_content' ]
2579 2586
         );
2580 2587
 
  2588
+        if ( strlen( $pod[ 'label' ] ) < 1 )
  2589
+            $pod[ 'label' ] = $pod[ 'name' ];
  2590
+
2581 2591
         // @todo update with a method to put all options in
2582 2592
         $defaults = array(
2583  
-            'is_toplevel' => 1,
  2593
+            'show_in_menu' => 1,
2584 2594
             'type' => 'post_type',
2585 2595
             'storage' => 'meta',
2586 2596
             'object' => '',
@@ -2650,7 +2660,7 @@ public function load_pods ( $params = null ) {
2650 2660
         $params = (object) pods_sanitize( $params );
2651 2661
 
2652 2662
         $order = 'ASC';
2653  
-        $orderby = 'menu_order';
  2663
+        $orderby = 'menu_order title';
2654 2664
         $limit = -1;
2655 2665
 
2656 2666
         $meta_query = array();
@@ -2722,7 +2732,7 @@ public function load_pods ( $params = null ) {
2722 2732
         else
2723 2733
             $cache_key = 'pods_get' . $cache_key;
2724 2734
 
2725  
-        if ( ( 'pods' != $cache_key || empty( $meta_query ) ) && empty( $limit ) && ( empty ( $orderby ) || 'menu_order' == $orderby ) ) {
  2735
+        if ( ( 'pods' != $cache_key || empty( $meta_query ) ) && empty( $limit ) && ( empty ( $orderby ) || 'menu_order title' == $orderby ) ) {
2726 2736
             $the_pods = get_transient( $cache_key );
2727 2737
 
2728 2738
             if ( false !== $the_pods )
@@ -2943,10 +2953,10 @@ public function load_fields ( $params, $strict = false ) {
2943 2953
 
2944 2954
             foreach ( $pod[ 'fields' ] as $field ) {
2945 2955
                 if ( empty( $params->name ) && empty( $params->id ) && empty( $params->type ) )
2946  
-                    $fields[ $field[ 'id' ] ] = $field;
  2956
+                    $fields[ $field[ 'name' ] ] = $field;
2947 2957
 
2948 2958
                 if ( in_array( $fields[ 'name' ], $params->name ) || in_array( $fields[ 'id' ], $params->id ) || in_array( $fields[ 'type' ], $params->type ) )
2949  
-                    $fields[ $field[ 'id' ] ] = $field;
  2959
+                    $fields[ $field[ 'name' ] ] = $field;
2950 2960
             }
2951 2961
         }
2952 2962
         else {
@@ -2982,7 +2992,7 @@ public function load_fields ( $params, $strict = false ) {
2982 2992
                     ) );
2983 2993
 
2984 2994
                     if ( empty( $params->type ) || in_array( $fields[ 'type' ], $params->type ) )
2985  
-                        $fields[ $field[ 'id' ] ] = $field;
  2995
+                        $fields[ $field[ 'name' ] ] = $field;
2986 2996
                 }
2987 2997
             }
2988 2998
         }
4  classes/PodsAdmin.php
@@ -147,7 +147,7 @@ public function admin_head () {
147 147
     public function admin_menu () {
148 148
         $submenu = array();
149 149
 
150  
-        $results = $this->api->load_pods( array( //'options' => array('disable_manage' => 0),
  150
+        $results = $this->api->load_pods( array(
151 151
             'type' => 'pod'
152 152
         ) );
153 153
 
@@ -162,7 +162,7 @@ public function admin_menu () {
162 162
                 $item[ 'options' ][ 'label' ] = ( !empty( $item[ 'options' ][ 'label' ] ) ) ? $item[ 'options' ][ 'label' ] : ucwords( str_replace( '_', ' ', $item[ 'name' ] ) );
163 163
                 $item[ 'options' ][ 'label' ] = apply_filters( 'pods_admin_menu_label', $item[ 'options' ][ 'label' ], $item );
164 164
 
165  
-                if ( 1 == $item[ 'options' ][ 'is_toplevel' ] ) {
  165
+                if ( 1 == $item[ 'options' ][ 'show_in_menu' ] ) {
166 166
                     add_object_page( $item[ 'options' ][ 'label' ], $item[ 'options' ][ 'label' ], 'read', "pods-manage-{$item['name']}" );
167 167
 
168 168
                     if ( is_super_admin() || current_user_can( 'pods_edit_' . $item[ 'name' ] ) || current_user_can( 'pods_delete_' . $item[ 'name' ] ) ) {
23  classes/PodsUI.php
@@ -54,6 +54,7 @@ class PodsUI
54 54
     public $searchable = true;
55 55
     public $sortable = true;
56 56
     public $pagination = true;
  57
+    public $pagination_total = true;
57 58
     public $export = array('on' => false,
58 59
                            'formats' => array('csv' => ',',
59 60
                                               'tsv' => "\t",
@@ -1223,11 +1224,11 @@ public function manage ($reorder = false) {
1223 1224
 <?php
1224 1225
         }
1225 1226
 
1226  
-        if (!empty($this->data) && ( false !== $this->pagination || ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && !in_array( 'delete', $this->actions_hidden ) && false !== $this->reorder[ 'on' ] ) ) || ( !in_array( 'export', $this->actions_disabled ) && !in_array( 'export', $this->actions_hidden ) ) ) {
  1227
+        if (!empty($this->data) && ( false !== $this->pagination_total || false !== $this->pagination || ( true === $reorder && !in_array( 'reorder', $this->actions_disabled ) && !in_array( 'delete', $this->actions_hidden ) && false !== $this->reorder[ 'on' ] ) ) || ( !in_array( 'export', $this->actions_disabled ) && !in_array( 'export', $this->actions_hidden ) ) ) {
1227 1228
 ?>
1228 1229
         <div class="tablenav">
1229 1230
 <?php
1230  
-            if (false !== $this->pagination) {
  1231
+            if ( false !== $this->pagination_total || false !== $this->pagination ) {
1231 1232
 ?>
1232 1233
             <div class="tablenav-pages<?php echo ($this->limit < $this->total_found || 1 < $this->page) ? '' : ' one-page'; ?>">
1233 1234
                 <?php $this->pagination(1); ?>
@@ -1295,7 +1296,7 @@ public function manage ($reorder = false) {
1295 1296
         </div>
1296 1297
 <?php
1297 1298
             }*/
1298  
-            if (false !== $this->pagination) {
  1299
+            if ( false !== $this->pagination_total || false !== $this->pagination ) {
1299 1300
 ?>
1300 1301
         <div class="tablenav">
1301 1302
             <div class="tablenav-pages<?php echo ($this->limit < $this->total_found || 1 < $this->page) ? '' : ' one-page'; ?>">
@@ -1849,15 +1850,20 @@ public function pagination ($header = false) {
1849 1850
             return call_user_func($this->actions_custom['pagination'], $header, $this);
1850 1851
         $total_pages = ceil($this->total_found / $this->limit);
1851 1852
         $request_uri = pods_var_update(array('pg' . $this->num => ''), array('limit' . $this->num, 'orderby' . $this->num, 'orderby_dir' . $this->num, 'search' . $this->num), $this->exclusion());
  1853
+
  1854
+        if ( false !== $this->pagination_total ) {
1852 1855
 ?>
1853 1856
     <span class="displaying-num"><?php echo $this->total_found; ?> item<?php echo (1 == $this->total_found) ? '' : 's'; ?></span>
1854 1857
 <?php
1855  
-        if (1 < $total_pages) {
  1858
+        }
  1859
+
  1860
+        if ( false !== $this->pagination ) {
  1861
+            if (1 < $total_pages) {
1856 1862
 ?>
1857 1863
     <a class="first-page<?php echo (1 < $this->page) ? '' : ' disabled'; ?>" title="<?php _e('Go to the first page', 'pods'); ?>" href="<?php echo $request_uri; ?>">&laquo;</a>
1858 1864
     <a class="prev-page<?php echo (1 < $this->page) ? '' : ' disabled'; ?>" title="<?php _e('Go to the previous page', 'pods'); ?>" href="<?php echo $request_uri; ?>&pg<?php echo $this->num; ?>=<?php echo max($this->page - 1, 1); ?>">&lsaquo;</a>
1859 1865
 <?php
1860  
-            if (true == $header) {
  1866
+                if (true == $header) {
1861 1867
 ?>
1862 1868
     <span class="paging-input"><input class="current-page" title="<?php _e('Current page', 'pods'); ?>" type="text" name="pg<?php echo $this->num; ?>" value="<?php echo $this->page; ?>" size="<?php echo strlen($total_pages); ?>"> <?php _e('of', 'pods'); ?> <span class="total-pages"><?php echo $total_pages; ?></span></span>
1863 1869
     <script>
@@ -1872,16 +1878,17 @@ public function pagination ($header = false) {
1872 1878
         });
1873 1879
     </script>
1874 1880
 <?php
1875  
-            }
1876  
-            else {
  1881
+                }
  1882
+                else {
1877 1883
 ?>
1878 1884
     <span class="paging-input"><?php echo $this->page; ?> <?php _e('of', 'pods'); ?> <span class="total-pages"><?php echo $total_pages; ?></span></span>
1879 1885
 <?php
1880  
-            }
  1886
+                }
1881 1887
 ?>
1882 1888
     <a class="next-page<?php echo ($this->page < $total_pages) ? '' : ' disabled'; ?>" title="<?php _e('Go to the next page', 'pods'); ?>" href="<?php echo $request_uri; ?>&pg<?php echo $this->num; ?>=<?php echo min($this->page + 1, $total_pages); ?>">&rsaquo;</a>
1883 1889
     <a class="last-page<?php echo ($this->page < $total_pages) ? '' : ' disabled'; ?>" title="<?php _e('Go to the last page', 'pods'); ?>'" href="<?php echo $request_uri; ?>&pg<?php echo $this->num; ?>=<?php echo $total_pages; ?>">&raquo;</a>
1884 1890
 <?php
  1891
+            }
1885 1892
         }
1886 1893
     }
1887 1894
 
291  sql/PodsUpgrade.php
@@ -10,8 +10,11 @@ class PodsUpgrade_2_0 {
10 10
 
11 11
     public $tables = array();
12 12
 
  13
+    private $progress = array();
  14
+
13 15
     function __construct () {
14 16
         $this->get_tables();
  17
+        $this->get_progress();
15 18
     }
16 19
 
17 20
     function get_tables () {
@@ -21,11 +24,29 @@ function get_tables () {
21 24
 
22 25
         if ( !empty( $tables ) ) {
23 26
             foreach ( $tables as $table ) {
24  
-                $this->tables[ ] = $table[ 0 ];
  27
+                $this->tables[] = $table[ 0 ];
25 28
             }
26 29
         }
27 30
     }
28 31
 
  32
+    function get_progress () {
  33
+        $methods = get_class_methods( $this );
  34
+
  35
+        foreach ( $methods as $method ) {
  36
+            if ( 0 === strpos( $method, 'migrate_' ) ) {
  37
+                $this->progress[ str_replace( 'migrate_', '', $method ) ] = false;
  38
+
  39
+                if ( 'migrate_pod' == $method )
  40
+                    $this->progress[ str_replace( 'migrate_', '', $method ) ] = array();
  41
+            }
  42
+        }
  43
+
  44
+        $progress = (array) get_option( 'pods_framework_upgrade_2_0', array() );
  45
+
  46
+        if ( !empty( $progress ) )
  47
+            $this->progress = array_merge( $this->progress, $progress );
  48
+    }
  49
+
29 50
     function install () {
30 51
         global $wpdb;
31 52
 
@@ -161,6 +182,9 @@ function prepare_pod ( $params ) {
161 182
     }
162 183
 
163 184
     function migrate_pods () {
  185
+        if ( true === $this->check_progress( __FUNCTION__ ) )
  186
+            return '1';
  187
+
164 188
         $api = pods_api();
165 189
 
166 190
         $pod_types = pods_query( "SELECT * FROM `@wp_pod_types`", false );
@@ -207,6 +231,12 @@ function migrate_pods () {
207 231
             $weight = 4;
208 232
 
209 233
             foreach ( $field_rows as $row ) {
  234
+                if ( 'name' == $row->name )
  235
+                    continue;
  236
+
  237
+                if ( in_array( $row->name, array( 'created', 'modified', 'author' ) ) )
  238
+                    $row->name .= '2';
  239
+
210 240
                 $field_type = $row->coltype;
211 241
 
212 242
                 if ( 'txt' == $field_type )
@@ -219,8 +249,8 @@ function migrate_pods () {
219 249
                     $field_type = 'number';
220 250
 
221 251
                 $field_params = array(
222  
-                    'name' => $row->name,
223  
-                    'label' => $row->label,
  252
+                    'name' => trim( $row->name ),
  253
+                    'label' => trim( $row->label ),
224 254
                     'type' => $field_type,
225 255
                     'weight' => $weight,
226 256
                     'options' => array(
@@ -231,7 +261,26 @@ function migrate_pods () {
231 261
                 );
232 262
 
233 263
                 if ( 'pick' == $field_type ) {
  264
+                    $field_params[ 'pick_object' ] = 'pod';
234 265
                     $field_params[ 'pick_val' ] = $row->pickval;
  266
+
  267
+                    if ( 'wp_user' == $row->pickval ) {
  268
+                        $field_params[ 'pick_object' ] = 'user';
  269
+                        $field_params[ 'pick_val' ] = '';
  270
+                    }
  271
+                    elseif ( 'wp_post' == $row->pickval ) {
  272
+                        $field_params[ 'pick_object' ] = 'post_type';
  273
+                        $field_params[ 'pick_val' ] = 'post';
  274
+                    }
  275
+                    elseif ( 'wp_page' == $row->pickval ) {
  276
+                        $field_params[ 'pick_object' ] = 'post_type';
  277
+                        $field_params[ 'pick_val' ] = 'page';
  278
+                    }
  279
+                    elseif ( 'wp_taxonomy' == $row->pickval ) {
  280
+                        $field_params[ 'pick_object' ] = 'taxonomy';
  281
+                        $field_params[ 'pick_val' ] = 'category';
  282
+                    }
  283
+
235 284
                     $field_params[ 'sister_field_id' ] = $row->sister_field_id;
236 285
                     $field_params[ 'pick_filter' ] = $row->pick_filter;
237 286
                     $field_params[ 'pick_orderby' ] = $row->pick_orderby;
@@ -280,41 +329,127 @@ function migrate_pods () {
280 329
 
281 330
         $this->get_tables();
282 331
 
  332
+        $this->update_progress( __FUNCTION__, true );
  333
+
  334
+        return '1';
  335
+    }
  336
+
  337
+    function migrate_fields () {
283 338
         return '1';
284 339
     }
285 340
 
286 341
     function migrate_relationships () {
287  
-        // go through each relationship row
288  
-        // convert pod_id to real table id of item
289  
-            // lookup pod_id in wp_pod as id field, get tbl_row_id
290  
-        // get real pod_id (Pod ID) of the item being related from
291  
-            // get datatype field that matches id = pod_id
292  
-        // get real relate_pod_id (Pod ID) of the item being related to (if pod)
293  
-            // you can get this by looking at what object the field is related to
294  
-            // or if a sister_pod_id is given, look up that in wp_pod
295  
-        // copy tbl_row_id to related_item_id
296  
-        // copy weight
297  
-
298  
-        // OLD TABLE:
299  
-        /*
300  
-            `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
301  
-            `pod_id` BIGINT(15) UNSIGNED NULL DEFAULT NULL,
302  
-            `sister_pod_id` BIGINT(15) UNSIGNED NULL DEFAULT NULL,
303  
-            `field_id` INT(10) UNSIGNED NULL DEFAULT NULL,
304  
-            `tbl_row_id` BIGINT(15) UNSIGNED NULL DEFAULT NULL,
305  
-            `weight` INT(10) UNSIGNED NULL DEFAULT '0'
306  
-        */
307  
-        // NEW TABLE:
308  
-        /*
309  
-            `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
310  
-            `pod_id` INT(10) UNSIGNED NULL DEFAULT NULL,
311  
-            `field_id` INT(10) UNSIGNED NULL DEFAULT NULL,
312  
-            `item_id` BIGINT(20) UNSIGNED NULL DEFAULT NULL,
313  
-            `related_pod_id` INT(10) UNSIGNED NULL DEFAULT NULL,
314  
-            `related_field_id` INT(10) UNSIGNED NULL DEFAULT NULL,
315  
-            `related_item_id` BIGINT(20) UNSIGNED NULL DEFAULT NULL,
316  
-            `weight` SMALLINT(5) UNSIGNED NULL DEFAULT '0'
317  
-        */
  342
+        if ( true === $this->check_progress( __FUNCTION__ ) )
  343
+            return '1';
  344
+
  345
+        global $wpdb;
  346
+
  347
+        $api = pods_api();
  348
+
  349
+        $last_id = (int) $this->check_progress( __FUNCTION__ );
  350
+
  351
+        $sql = "
  352
+            SELECT *
  353
+            FROM `@wp_pod_rel`
  354
+            WHERE {$last_id} < `id`
  355
+            ORDER BY `id`
  356
+            LIMIT 0, 800
  357
+        ";
  358
+
  359
+        $rel = pods_query( $sql );
  360
+
  361
+        $last_id = true;
  362
+
  363
+        $pod_types = pods_query( "SELECT `id`, `name` FROM `@wp_pod_types` ORDER BY `id`" );
  364
+
  365
+        $types = array();
  366
+
  367
+        $x = 0;
  368
+
  369
+        if ( !empty( $rel ) && !empty( $pod_types ) ) {
  370
+            foreach ( $pod_types as $type ) {
  371
+                $types[ $type->id ] = $api->load_pod( array( 'name' => $type->name ) );
  372
+
  373
+                $pod_fields = pods_query( "SELECT `id`, `name` FROM `@wp_pod_fields` WHERE `datatype` = {$type->id} ORDER BY `id`" );
  374
+
  375
+                foreach ( $pod_fields as $field ) {
  376
+                    $types[ 'old_fields' ][ $field->id ] = $field->name;
  377
+                }
  378
+            }
  379
+
  380
+            foreach ( $rel as $r ) {
  381
+                $r->pod_id = (int) $r->pod_id;
  382
+
  383
+                $p = pods_query( "SELECT `tbl_row_id`, `datatype` FROM `@wp_pod` WHERE `id` = {$r->pod_id}");
  384
+
  385
+                if ( empty( $p ) )
  386
+                    continue;
  387
+
  388
+                if ( !isset( $types[ $p->datatype ] ) || !isset( $types[ $p->datatype ][ 'old_fields' ][ $r->field_id ] ) )
  389
+                    continue;
  390
+
  391
+                if ( !isset( $types[ $p->datatype ][ 'fields' ][ $types[ $p->datatype ][ 'old_fields' ][ $r->field_id ] ] ) )
  392
+                    continue;
  393
+
  394
+                $field = $types[ $p->datatype ][ 'fields' ][ $types[ $p->datatype ][ 'old_fields' ][ $r->field_id ] ];
  395
+
  396
+                if ( !in_array( $field[ 'type' ], array( 'pick', 'file' ) ) )
  397
+                    continue;
  398
+
  399
+                $pod_id = $types[ $p->datatype ][ 'id' ];
  400
+                $field_id = $field[ 'id' ];
  401
+                $item_id = $p->tbl_row_id;
  402
+
  403
+                $related_pod_id = 0;
  404
+                $related_field_id = 0;
  405
+                $related_item_id = $r->tbl_row_id;
  406
+
  407
+                if ( 'pick' == $field[ 'type' ] ) {
  408
+                    if ( 0 < (int) $field[ 'sister_field_id' ] ) {
  409
+                        $related_field = $api->load_field( array( 'id' => $field[ 'sister_field_id' ] ) );
  410
+
  411
+                        if ( empty( $related_field ) )
  412
+                            continue;
  413
+
  414
+                        $related_pod_id = $related_field[ 'pod_id' ];
  415
+                        $related_field_id = $related_field[ 'id' ];
  416
+                    }
  417
+                    elseif ( 'pod' == $field[ 'pick_object' ] && 0 < strlen( $field[ 'pick_val' ] ) ) {
  418
+                        $related_pod = $api->load_pod( array( 'name' => $field[ 'pick_val' ] ), false );
  419
+
  420
+                        if ( empty( $related_pod ) )
  421
+                            continue;
  422
+
  423
+                        $related_pod_id = $related_pod[ 'id' ];
  424
+                    }
  425
+                }
  426
+
  427
+                $sql = "
  428
+                    REPLACE INTO `@wp_pods_rel`
  429
+                    ( `id`, `pod_id`, `field_id`, `item_id`, `related_pod_id`, `related_field_id`, `related_item_id`, `weight` )
  430
+                    VALUES ( {$r->id}, {$pod_id}, {$field_id}, {$item_id}, {$related_pod_id}, {$related_field_id}, {$related_item_id}, {$r->weight} )
  431
+                ";
  432
+
  433
+                pods_query( $sql );
  434
+
  435
+                $last_id = $r->id;
  436
+
  437
+                $x++;
  438
+
  439
+                if ( 10 < $x ) {
  440
+                    $this->update_progress( __FUNCTION__, $last_id );
  441
+
  442
+                    $x = 0;
  443
+                }
  444
+            }
  445
+        }
  446
+
  447
+        $this->update_progress( __FUNCTION__, $last_id );
  448
+
  449
+        if ( 800 == count( $rel ) )
  450
+            echo '-2';
  451
+        else
  452
+            echo '1';
318 453
     }
319 454
 
320 455
     function migrate_settings () {
@@ -322,6 +457,9 @@ function migrate_settings () {
322 457
     }
323 458
 
324 459
     function migrate_roles () {
  460
+        if ( true === $this->check_progress( __FUNCTION__ ) )
  461
+            return '1';
  462
+
325 463
         global $wpdb;
326 464
 
327 465
         $wp_roles = get_option( "{$wpdb->prefix}user_roles" );
@@ -364,10 +502,15 @@ function migrate_roles () {
364 502
 
365 503
         update_option( "{$wpdb->prefix}user_roles", $wp_roles );
366 504
 
  505
+        $this->update_progress( __FUNCTION__, true );
  506
+
367 507
         return '1';
368 508
     }
369 509
 
370 510
     function migrate_templates () {
  511
+        if ( true === $this->check_progress( __FUNCTION__ ) )
  512
+            return '1';
  513
+
371 514
         $api = pods_api();
372 515
 
373 516
         $templates = pods_query( "SELECT * FROM `@wp_pod_templates`", false );
@@ -386,10 +529,15 @@ function migrate_templates () {
386 529
             $results[] = $api->save_template( $params );
387 530
         }
388 531
 
  532
+        $this->update_progress( __FUNCTION__, true );
  533
+
389 534
         return '1';
390 535
     }
391 536
 
392 537
     function migrate_pages () {
  538
+        if ( true === $this->check_progress( __FUNCTION__ ) )
  539
+            return '1';
  540
+
393 541
         $api = pods_api();
394 542
 
395 543
         $pages = pods_query( "SELECT * FROM `@wp_pod_pages`", false );
@@ -403,10 +551,15 @@ function migrate_pages () {
403 551
             $results[] = $api->save_page( $page );
404 552
         }
405 553
 
  554
+        $this->update_progress( __FUNCTION__, true );
  555
+
406 556
         return '1';
407 557
     }
408 558
 
409 559
     function migrate_helpers () {
  560
+        if ( true === $this->check_progress( __FUNCTION__ ) )
  561
+            return '1';
  562
+
410 563
         $api = pods_api();
411 564
 
412 565
         $helpers = pods_query( "SELECT * FROM `@wp_pod_helpers`", false );
@@ -426,6 +579,8 @@ function migrate_helpers () {
426 579
             $results[] = $api->save_helper( $params );
427 580
         }
428 581
 
  582
+        $this->update_progress( __FUNCTION__, true );
  583
+
429 584
         return '1';
430 585
     }
431 586
 
@@ -449,11 +604,30 @@ function migrate_pod ( $params ) {
449 604
         if ( !in_array( "{$wpdb->prefix}pod", $this->tables ) )
450 605
             return pods_error( __( 'Pod table not found, items cannot be migrated', 'pods' ) );
451 606
 
  607
+        if ( true === $this->check_progress( __FUNCTION__, $pod ) )
  608
+            return '1';
  609
+
  610
+        $pod_data = pods_api()->load_pod( array( 'name' => $pod ) );
  611
+
  612
+        if ( empty( $pod_data ) )
  613
+            return pods_error( __( 'Pod not found, items cannot be migrated', 'pods' ) );
  614
+
  615
+        $columns = array();
  616
+
  617
+        foreach ( $pod_data[ 'fields' ] as $field ) {
  618
+            if ( !in_array( $field[ 'name' ], array( 'created', 'modified', 'author' ) ) && !in_array( $field[ 'type' ], array( 'file', 'pick' ) ) )
  619
+                $columns[] = pods_sanitize( $field[ 'name' ] );
  620
+        }
  621
+
  622
+        $select = '`t`.`id`, `t`.`' . implode( '`, `t`.`', $columns ) . '`';
  623
+        $columns = '`id`, `' . implode( '`, `', $columns ) . '`';
  624
+
452 625
         // Copy content from the old table into the new
453 626
         $sql = "
454  
-            SELECT *
455  
-            INTO `@wp_pods_tbl_{$pod}`
456  
-            FROM `@wp_pod_tbl_{$pod}`
  627
+            REPLACE INTO `@wp_pods_tbl_{$pod}`
  628
+                ( {$columns} )
  629
+                ( SELECT {$select}
  630
+                  FROM `@wp_pod_tbl_{$pod}` AS `t` )
457 631
         ";
458 632
 
459 633
         pods_query( $sql );
@@ -469,6 +643,19 @@ function migrate_pod ( $params ) {
469 643
 
470 644
         pods_query( $sql );
471 645
 
  646
+        // Copy name data from the old index table into the new individual table (if name empty in indiv table)
  647
+        $sql = "
  648
+            UPDATE `@wp_pods_tbl_{$pod}` AS `t`
  649
+            LEFT JOIN `@wp_pod_types` AS `x` ON `x`.`name` = '{$pod}'
  650
+            LEFT JOIN `@wp_pod` AS `p` ON `p`.`datatype` = `x`.`id` AND `p`.`tbl_row_id` = `t`.`id`
  651
+            SET `t`.`name` = `p`.`name`
  652
+            WHERE ( `t`.`name` IS NULL OR `t`.`name` = '' ) AND `x`.`id` IS NOT NULL AND `p`.`id` IS NOT NULL
  653
+        ";
  654
+
  655
+        pods_query( $sql );
  656
+
  657
+        $this->update_progress( __FUNCTION__, true, $pod );
  658
+
472 659
         return '1';
473 660
     }
474 661
 
@@ -479,6 +666,8 @@ function restart () {
479 666
             if ( false !== strpos( $table, "{$wpdb->prefix}pods" ) )
480 667
                 pods_query( "TRUNCATE `{$table}`", false );
481 668
         }
  669
+
  670
+        delete_option( 'pods_framework_upgrade_2_0' );
482 671
     }
483 672
 
484 673
     function cleanup () {
@@ -491,8 +680,10 @@ function cleanup () {
491 680
 
492 681
         delete_option( 'pods_roles' );
493 682
         delete_option( 'pods_version' );
  683
+        delete_option( 'pods_framework_upgrade_2_0' );
494 684
 
495  
-        /* other options maybe not in 2.0
  685
+        /*
  686
+         * other options maybe not in 2.0
496 687
         delete_option( 'pods_disable_file_browser' );
497 688
         delete_option( 'pods_files_require_login' );
498 689
         delete_option( 'pods_files_require_login_cap' );
@@ -502,4 +693,28 @@ function cleanup () {
502 693
         delete_option( 'pods_page_precode_timing' );
503 694
         */
504 695
     }
  696
+
  697
+    function update_progress ( $method, $v, $x = null ) {
  698
+        $method = str_replace( 'migrate_', '', $method );
  699
+
  700
+        if ( null !== $x )
  701
+            $this->progress[ $method ][ $x ] = (boolean) $v;
  702
+        else
  703
+            $this->progress[ $method ] = $v;
  704
+
  705
+        update_option( 'pods_framework_upgrade_2_0', $this->progress );
  706
+    }
  707
+
  708
+    function check_progress ( $method, $x = null ) {
  709
+        $method = str_replace( 'migrate_', '', $method );
  710
+
  711
+        if ( isset( $this->progress[ $method ] ) ) {
  712
+            if ( null === $x )
  713
+                return $this->progress[ $method ];
  714
+            elseif ( isset( $this->progress[ $method ][ $x ] ) )
  715
+                return (boolean) $this->progress[ $method ][ $x ];
  716
+        }
  717
+
  718
+        return false;
  719
+    }
505 720
 }
23  ui/admin/upgrade.php
@@ -41,18 +41,18 @@
41 41
                 <p><em><?php _e( '', 'pods' ); ?></em></p>
42 42
                 <div id="pods-wizard-options">
43 43
                     <div class="pods-wizard-option">
44  
-                        <a href="#">
  44
+                        <a href="http://vaultpress.com/podsframework/" target="_blank">
45 45
                             <img src="<?php echo PODS_URL; ?>/ui/images/logo_vaultpress.png" alt="Vaultpress" />
46 46
                             <p><?php _e( '1 free month', 'pods' ); ?></p>
47  
-                            <p><?php _e( 'Coupon Code', 'pods' ); ?>: <strong>ABC123</strong></p>
  47
+                            <p><strong><?php _e ( 'Click to sign up', 'pods' ); ?></strong></p>
48 48
                         </a>
49 49
                         <p><em><?php _e( 'A service that provides realtime continuous backups, restores, and security scanning.', 'pods' ); ?></em></p>
50 50
                     </div>
51 51
                     <div class="pods-wizard-option">
52  
-                        <a href="#">
  52
+                        <a href="http://ithemes.com/member/go.php?r=31250&i=l44" target="_blank">
53 53
                             <img src="<?php echo PODS_URL; ?>/ui/images/logo_backupbuddy.png" alt="Backup Buddy" />
54 54
                             <p><?php _e( 'Receive 25% off', 'pods' ); ?></p>
55  
-                            <p><?php _e( 'Coupon Code', 'pods' ); ?>: <strong>ABC123</strong></p>
  55
+                            <p><?php _e( 'Coupon Code', 'pods' ); ?>: <strong>PODS25</strong></p>
56 56
                         </a>
57 57
                         <p><em><?php _e( 'The all-in-one WordPress backup plugin to easily backup, restore, and migrate to any number of local or external locations.', 'pods' ); ?></em></p>
58 58
                     </div>
@@ -63,7 +63,7 @@
63 63
             <!-- Prepare Panel -->
64 64
             <div id="pods-wizard-panel-2" class="pods-wizard-panel">
65 65
                 <div class="pods-wizard-content">
66  
-                    <p><?php _e( '', 'pods' ); ?></p>
  66
+                    <p><?php _e( 'We will prepare all of your Pods, Settings, and Content for migration. If any issues are found they will be displayed below for your review. Be sure to backup your database before continuing onto the next step for Migration.', 'pods' ); ?></p>
67 67
                 </div>
68 68
                 <table cellpadding="0" cellspacing="0">
69 69
                     <col style="width: 70px">
@@ -71,18 +71,19 @@
71 71
                     <col style="width: 580px">
72 72
                     <thead>
73 73
                         <tr>
74  
-                            <th colspan="3"><?php _e( 'Your Content', 'pods' ); ?></th>
  74
+                            <th colspan="3"><?php _e( 'Preparing Your Content for Migration', 'pods' ); ?>..</th>
75 75
                         </tr>
76 76
                     </thead>
77 77
                     <tbody><!-- complete|pending|active <i></i> -->
78 78
                         <?php
79 79
                             $pods = $wpdb->get_results( "SELECT `name`, `label` FROM `{$wpdb->prefix}pod_types` ORDER BY `name`" );
  80
+                            $count = count( $pods );
80 81
                         ?>
81  
-                        <tr class="pods-wizard-table-complete" data-upgrade="pods">
  82
+                        <tr class="pods-wizard-table-<?php echo ( 0 < $count ? 'complete' : 'pending' ); ?>" data-upgrade="pods">
82 83
                             <td class="pods-wizard-right pods-wizard-status">
83 84
                                 <i><img src="<?php echo PODS_URL; ?>/ui/images/spinner.gif" alt="Loading..." /></i>
84 85
                             </td>
85  
-                            <td class="pods-wizard-right pods-wizard-count"><?php echo count( $pods ); ?></td>
  86
+                            <td class="pods-wizard-right pods-wizard-count"><?php echo ( 0 < $count ? $count : '&mdash;' ); ?></td>
86 87
                             <td class="pods-wizard-name">
87 88
                                 <?php _e( 'Pods', 'pods' ); ?>
88 89
                                 <span class="pods-wizard-info"></span>
@@ -172,7 +173,7 @@
172 173
             <!-- Migrate Panel -->
173 174
             <div id="pods-wizard-panel-3" class="pods-wizard-panel">
174 175
                 <div class="pods-wizard-content">
175  
-                    <p><?php _e( '', 'pods' ); ?></p>
  176
+                    <p><?php _e( 'During this process your Pods, Settings, and Content will be migrated into the optimized Pods 2.0 architecture. We will not delete any of your old data, the tables will remain until you choose to clean them up after a successful upgrade.', 'pods' ); ?></p>
176 177
                 </div>
177 178
                 <table cellpadding="0" cellspacing="0">
178 179
                     <col style="width: 70px">
@@ -180,7 +181,7 @@
180 181
                     <col style="width: 580px">
181 182
                     <thead>
182 183
                         <tr>
183  
-                            <th colspan="3"><?php _e( 'Your Content', 'pods' ); ?></th>
  184
+                            <th colspan="3"><?php _e( 'Migrating Your Content', 'pods' ); ?>..</th>
184 185
                         </tr>
185 186
                     </thead>
186 187
                     <tbody><!-- complete|pending|active <i></i> -->
@@ -188,7 +189,7 @@
188 189
                             <td class="pods-wizard-right pods-wizard-status">
189 190
                                 <i><img src="<?php echo PODS_URL; ?>/ui/images/spinner.gif" alt="Loading..." /></i>
190 191
                             </td>
191  
-                            <td class="pods-wizard-right pods-wizard-count"><?php echo count( $pods ); ?></td>
  192
+                            <td class="pods-wizard-right pods-wizard-count"><?php echo ( 0 < $count ? $count : '&mdash;' ); ?></td>
192 193
                             <td class="pods-wizard-name">
193 194
                                 <?php _e( 'Pods', 'pods' ); ?>
194 195
                                 <span class="pods-wizard-info"></span>
49  ui/js/jquery.pods.upgrade.js
@@ -64,7 +64,7 @@
64 64
                 $( '#pods-wizard-next' ).show();
65 65
             }
66 66
         },
67  
-        migrate : function () {
  67
+        migrate : function ( postdata ) {
68 68
             var pods_ajaxurl = $( '#pods-wizard-box' ).data( 'url' );
69 69
 
70 70
             if ( 'undefined' != typeof pods_ajaxurl )
@@ -73,22 +73,24 @@
73 73
             if ( 'undefined' != typeof ajaxurl && ('undefined' == typeof pods_ajaxurl || '' == pods_ajaxurl || '?pods_ajax=1' == pods_ajaxurl || document.location.href == pods_ajaxurl || document.location.href.replace( /\?nojs\=1/, '?pods_ajax=1' ) == pods_ajaxurl) )
74 74
                 pods_ajaxurl = ajaxurl + '?pods_ajax=1';
75 75
 
76  
-            if ( $( '#pods-wizard-panel-3 table tbody tr.pods-wizard-table-pending' )[ 0 ] ) {
77  
-                var $row = $( '#pods-wizard-panel-3 table tbody tr.pods-wizard-table-pending' ).first();
  76
+            if ( 'undefined' != typeof postdata || $( '#pods-wizard-panel-3 table tbody tr.pods-wizard-table-pending' )[ 0 ] ) {
  77
+                if ( 'undefined' == typeof postdata ) {
  78
+                    var $row = $( '#pods-wizard-panel-3 table tbody tr.pods-wizard-table-pending' ).first();
78 79
 
79  
-                $row.removeClass( 'pods-wizard-table-pending' ).addClass( 'pods-wizard-table-active' );
  80
+                    $row.removeClass( 'pods-wizard-table-pending' ).addClass( 'pods-wizard-table-active' );
80 81
 
81  
-                var postdata = {
82  
-                    'action' : $( '#pods-wizard-box' ).data( 'action' ),
83  
-                    'method' : $( '#pods-wizard-box' ).data( 'method' ),
84  
-                    '_wpnonce' : $( '#pods-wizard-box' ).data( '_wpnonce' ),
85  
-                    'step' : 'migratexx',
86  
-                    'type' : $row.data( 'upgrade' ),
87  
-                    'pod' : ''
88  
-                };
  82
+                    var postdata = {
  83
+                        'action' : $( '#pods-wizard-box' ).data( 'action' ),
  84
+                        'method' : $( '#pods-wizard-box' ).data( 'method' ),
  85
+                        '_wpnonce' : $( '#pods-wizard-box' ).data( '_wpnonce' ),
  86
+                        'step' : 'migrate',
  87
+                        'type' : $row.data( 'upgrade' ),
  88
+                        'pod' : ''
  89
+                    };
89 90
 
90  
-                if ( 'undefined' != typeof $row.data( 'pod' ) )
91  
-                    postdata[ 'pod' ] = $row.data( 'pod' );
  91
+                    if ( 'undefined' != typeof $row.data( 'pod' ) )
  92
+                        postdata[ 'pod' ] = $row.data( 'pod' );
  93
+                }
92 94
 
93 95
                 $.ajax( {
94 96
                     type : 'POST',
@@ -97,10 +99,21 @@
97 99
                     data : postdata,
98 100
                     success : function ( d ) {
99 101
                         if ( -1 == d.indexOf( '<e>' ) && -1 != d ) {
100  
-                            $row.removeClass( 'pods-wizard-table-active' ).addClass( 'pods-wizard-table-complete' );
101  
-
102  
-                            // Run next
103  
-                            return methods[ 'migrate' ]();
  102
+                            if ( -2 == d ) {
  103
+                                // Run next
  104
+                                return methods[ 'migrate' ]( postdata );
  105
+                            }
  106
+                            else {
  107
+                                $row.removeClass( 'pods-wizard-table-active' ).addClass( 'pods-wizard-table-complete' );
  108
+
  109
+                                // Run next
  110
+                                return methods[ 'migrate' ]();
  111
+                            }
  112
+                        }
  113
+                        else if ( -1 == d.indexOf( 'Database Error;' ) ) {
  114
+                            $row.removeClass( 'pods-wizard-table-active' ).addClass( 'pods-wizard-table-error' );
  115
+                            $row.find( 'td span.pods-wizard-info' ).html( d.replace( '<e>', '' ).replace( '</e>', '' ) );
  116
+                            console.log( d.replace( '<e>', '' ).replace( '</e>', '' ) );
104 117
                         }
105 118
                         else {
106 119
                             $row.removeClass( 'pods-wizard-table-active' ).addClass( 'pods-wizard-table-warning' );

No commit comments for this range

Something went wrong with that request. Please try again.