private function validate_data($data, $previous_field = null)
 {
     if (empty($data['field_name'])) {
         throw new AWPCP_Exception(__('You did not provide a name for the field.', 'awpcp-extra-fields'));
     }
     if (awpcp_extra_fields_is_reserved_name($data['field_name'])) {
         $message = __("You can't use <strong>%s</strong> as the name for the field. It is a WordPress Reserved Term.", 'awpcp-extra-fields');
         $message = sprintf($message, $data['field_name']);
         throw new AWPCP_Exception($message);
     }
     if (empty($data['field_label'])) {
         throw new AWPCP_Exception(__("You did not provide a post form label for the field.", 'awpcp-extra-fields'));
     }
     if (empty($data['field_label_view'])) {
         throw new AWPCP_Exception(__("You did not provide an ad view label for the field.", 'awpcp-extra-fields'));
     }
     if (empty($data['field_input_type'])) {
         throw new AWPCP_Exception(__("You did not indicate the input element type for the field.", 'awpcp-extra-fields'));
     }
     if (in_array($data['field_input_type'], array('Select', 'Select Multiple', 'Radio Button', 'Checkbox'))) {
         if (empty($data['field_options'])) {
             throw new AWPCP_Exception(__("You have indicated the field input type is either a checkbox, radio button or drop down element, however you did not provide any options for the field. You either need to change the input type to input box or textarea input or provide some options.", 'awpcp-extra-fields'));
         }
     }
     if (empty($data['field_mysql_data_type'])) {
         throw new AWPCP_Exception(__("You did not indicate the field MYSQL data type.", 'awpcp-extra-fields'));
     }
     if (is_null($previous_field) && awpcp_column_exists(AWPCP_TABLE_ADS, $data['field_name'])) {
         throw new AWPCP_Exception(__("Duplicate field name. You cannot use the same field name more than once.", 'awpcp-extra-fields'));
     }
 }
示例#2
0
 private function upgrade_to_1_0_0($version)
 {
     global $wpdb;
     /* add missing columns */
     if (!awpcp_column_exists(AWPCP_TABLE_EXTRA_FIELDS, 'field_privacy')) {
         $wpdb->query("ALTER TABLE " . AWPCP_TABLE_EXTRA_FIELDS . "  ADD `field_privacy` VARCHAR(255) COLLATE utf8_general_ci NOT NULL AFTER `field_validation`");
     }
     if (!awpcp_column_exists(AWPCP_TABLE_EXTRA_FIELDS, 'nosearch')) {
         $wpdb->query("ALTER TABLE " . AWPCP_TABLE_EXTRA_FIELDS . "  ADD `nosearch` VARCHAR(255) COLLATE utf8_general_ci ");
         $wpdb->query("UPDATE " . AWPCP_TABLE_EXTRA_FIELDS . "  SET `nosearch` = 0");
     }
     if (!awpcp_column_exists(AWPCP_TABLE_EXTRA_FIELDS, 'show_on_listings')) {
         $wpdb->query("ALTER TABLE " . AWPCP_TABLE_EXTRA_FIELDS . "  ADD `show_on_listings` VARCHAR(255) COLLATE utf8_general_ci ");
         // 1 = listings
         // 2 = single, the default for backward compatibility
         // 3 = both
         $wpdb->query("UPDATE " . AWPCP_TABLE_EXTRA_FIELDS . "  SET `show_on_listings` = '2'");
     }
     if (!awpcp_column_exists(AWPCP_TABLE_EXTRA_FIELDS, 'field_category')) {
         $wpdb->query("ALTER TABLE " . AWPCP_TABLE_EXTRA_FIELDS . "  ADD `field_category` VARCHAR(255) COLLATE utf8_general_ci AFTER `show_on_listings`");
     }
 }
示例#3
0
 private function upgrade_to_3_2_2($oldversion)
 {
     global $wpdb;
     if (!awpcp_column_exists(AWPCP_TABLE_MEDIA, 'status')) {
         $query = 'ALTER TABLE ' . AWPCP_TABLE_MEDIA . ' ADD `status` VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT %s AFTER `enabled`';
         $wpdb->query($wpdb->prepare($query, AWPCP_Media::STATUS_APPROVED));
     }
     if (get_awpcp_option('imagesapprove')) {
         update_option('awpcp-update-media-status', true);
         update_option('awpcp-pending-manual-upgrade', true);
     }
 }
示例#4
0
 public function ajax_migrate_regions_information()
 {
     global $wpdb;
     if (awpcp_column_exists(AWPCP_TABLE_ADS, 'ad_country')) {
         $cursor = get_option('awpcp-migrate-regions-info-cursor', 0);
         $total = $this->count_ads_pending_region_information_migration($cursor);
         $sql = 'SELECT ad_id, ad_country, ad_state, ad_city, ad_county_village ';
         $sql .= 'FROM ' . AWPCP_TABLE_ADS . ' ';
         $sql .= 'WHERE ad_id > %d ORDER BY ad_id LIMIT 0, 100';
         $results = $wpdb->get_results($wpdb->prepare($sql, $cursor));
         $regions = awpcp_basic_regions_api();
         foreach ($results as $ad) {
             $region = array();
             if (!empty($ad->ad_country)) {
                 $region['country'] = $ad->ad_country;
             }
             if (!empty($ad->ad_county_village)) {
                 $region['county'] = $ad->ad_county_village;
             }
             if (!empty($ad->ad_state)) {
                 $region['state'] = $ad->ad_state;
             }
             if (!empty($ad->ad_city)) {
                 $region['city'] = $ad->ad_city;
             }
             if (!empty($region)) {
                 // remove old data first
                 $regions->delete_by_ad_id($ad->ad_id);
                 $regions->save(array_merge(array('ad_id' => $ad->ad_id), $region));
             }
             $cursor = $ad->ad_id;
         }
         update_option('awpcp-migrate-regions-info-cursor', $cursor);
         $remaining = $this->count_ads_pending_region_information_migration($cursor);
         if (0 === $remaining) {
             // TODO: do this in the next version
             // $columns = array( 'ad_country, ad_state, ad_city, ad_county_village' );
             // foreach ( $columns as $column ) {
             //     $wpdb->query( sprintf( 'ALTER TABLE %s DROP COLUMN', AWPCP_TABLE_ADS, $column ) );
             // }
             // TODO: delete region_id column in a future upgrade and remove
             // all rows from ad_regions table that have no data in the country, county, state
             // and city columns.
             delete_option('awpcp-migrate-regions-information');
             $this->update_pending_upgrades_status();
         }
     } else {
         $total = 0;
         $remaining = 0;
     }
     return $this->ajax_response($total, $remaining);
 }