Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
handle
Jan 20, 2011

Bob Morales posted:

What are some common ways to refactor poo poo like this? Imagine functions.php with 500 functions just like this

PHP code:
function IsActiveEmp($EmpID) {
  $link=mysqli_connect("database","user","password") or die(mysqli_error());
  $db=mysqli_select_db("erp",$link) or die(mysqli_error());
  $query="SELECT Serial FROM TbfEmployee WHERE EmpID=".$EmpID." AND Active<>0;";
  $result=mysqli_query($query,$link) or die(mysqli_error());
  if(mysqli_num_rows($result)>0) {
    return true;
  } else {
    return false;
  }
}

rt4 posted:

Create an Employee class with an isActive() method that gets populated from the start when you load it from an EmployeeStorage interface via the GetById(int) method. You'll implement this interface several times over with a SQL version sitting at the bottom, then several decorators on top to handle things like validation and caching.

Or at least that's how I build business software.
Necroposting because I'm in the same situation and would love further details to understand this. Is there an article/example code that could help me visualize the latter? I'm almost comfortable reading basic OOP code at this point but haven't ever designed anything with it, and I don't think I can trust my gut to make the right design pattern-y choices yet.

Adbot
ADBOT LOVES YOU

handle
Jan 20, 2011

Thank you both! An immediate solution is great, this application just needs triage until it can be replaced in a few months.

handle
Jan 20, 2011

3rd edit: OK, maybe I understand enough now to try part 2 again. (Caveat: I've never worked with Wordpress.)

I'm guessing that you're using the Checkbox ACF field type for artist mediums/locations? ACF saves checkbox values as serialized arrays, and I found this article helpful to visualize why that creates problems with querying.

Since checkbox fields need to be queried using LIKE, searching for multiple selections in a checkbox should be doable by chaining single-term LIKE criteria with AND/OR. (i.e. wrapping individual key/value/compare arrays inside an array with the right relation set on the wrapper.)

I took a whack at a function that'll generate a chaining structure that WP_USER_QUERY should be able to parse, for whatever fields you want to multi-filter on, using similar syntax. Lemme know if it works! I unfortunately have no Wordpress install to test against.
PHP code:
$mediums = array('Wood', 'Paint');
$locations = array('Paris', 'London');

$args = array(
    'role' => 'artist',
    'orderby' => 'meta_value',
    'order' => 'ASC',
    'meta_query' => build_WP_Meta_Query_for_ACF_Checkbox(array(
        'relation' => 'AND',
        array(
            'artist_medium' => $mediums,
            'relation' => 'OR'
        ),
        array(
            'studio_region_location' => $locations,
            'relation' => 'OR'
        )
    ))
);
$user_query = new WP_USER_QUERY($args);

// TODO: appropriate error-handling! NO WARRANTY EXPRESSED OR IMPLIED, etc.
function build_WP_Meta_Query_for_ACF_Checkbox($criteria) {
    $result = array();
    // default relation should be 'AND', same as WP_Meta_Query.
    $result['relation'] = (isset($criteria['relation']) && strtoupper($criteria['relation']) === 'OR' ? 'OR' : 'AND');

    foreach ($criteria as $key => $value) {
        if (is_array($value)) {
            // "root" items have no named key, but are just array() wrappers for sub-query parts.
            if (!is_string($key)) {
                $sub_query = build_WP_Meta_Query_for_ACF_Checkbox($value);
                if (count($sub_query) > 0) {
                    $result[] = $sub_query;
                }
            } elseif (count($value) > 0) {
                // build up WP_Meta_Query args.
                foreach ($value as $val) {
                    $result[] = array(
                       'key' => $key,
                       // since the LIKE clause is querying a serialized array, we should
                       // enclose the search value in double quotes (at minimum.)
                       'value'=> '"' . $val . '"',
                       'compare' => 'LIKE'
                    );
                }
            }
        }
    }

    // our values for count() reflect that $result['relation'] is always set.
    if (count($result) <= 1) {
        // a checkbox field name was given, but had no search values.
        $result = array();
    } elseif (count($result) === 2) {
        // a checkbox field was provided with only one search value, and a relation is unnecessary.
        $result = $result[0];
    }
    return $result;
}

handle
Jan 20, 2011

Glad it helped! Did you ever figure out part one? I couldn't tell if that was an artifact of problems with part two, or something separate.

edit: btw, if you're still looking for help on the port, I sent you an email.

handle fucked around with this message at 18:19 on May 26, 2021

handle
Jan 20, 2011

Any idea what the ODBC driver version is? yitam's comment on GitHub suggests that the visible error message may be a result of ARM64 not being included as a processor type in the driver code, but as part of a code path that's intending to warn about ODBC not being installed.

Adbot
ADBOT LOVES YOU

handle
Jan 20, 2011

(Shooting from the hip here, not Windows-knowledgable. You may have already found these resources.)

Seems to be an issue with the cURL library in PHP, not the AWS SDK (similar issue.) I don't think you need to worry about setting a value for CApath. Based on the libcurl error page, I'd check if PHP has permissions to read cacert.pem.

Beyond that, another similar error was fixed by updating curl/openssl entries in php.ini to reflect the location of cacert.pem.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply