Giter Site home page Giter Site logo

singleton($step['class'])->extend('augmentSQL', $sql); in SearchIndex::getDirtyIDs() causes throwing Fatal Errors about silverstripe-fulltextsearch HOT 13 CLOSED

silverstripe avatar silverstripe commented on August 15, 2024
singleton($step['class'])->extend('augmentSQL', $sql); in SearchIndex::getDirtyIDs() causes throwing Fatal Errors

from silverstripe-fulltextsearch.

Comments (13)

UndefinedOffset avatar UndefinedOffset commented on August 15, 2024 1

I think all you'll need to do is update that one line referenced in #239 to fix it there, the same fix is needed in #240 but you also need to replace DataObject::singleton() as the singleton method is not in SilverStripe 3.x :). Hope that helps :)

from silverstripe-fulltextsearch.

michalkleiner avatar michalkleiner commented on August 15, 2024 1

Even with the updates the test getting the list of dirty IDs for has_many is failing. Will try to look into it more.

from silverstripe-fulltextsearch.

tractorcow avatar tractorcow commented on August 15, 2024

I think it does need to be fixed in fulltextsearch. That parameter is required in some cases.

from silverstripe-fulltextsearch.

dhensby avatar dhensby commented on August 15, 2024

If Translatable's signature is $dataQuery = null then it really shouldn't blindly expect an object...

@tractorcow how should we obtain a valid DataQuery in SearchIndex::getDirtyIDs() seeing as it doesn't seem to be using the ORM at all...

from silverstripe-fulltextsearch.

tractorcow avatar tractorcow commented on August 15, 2024

It's more = null for legacy reasons, that is we couldn't change the method signature. We should have in 4.0 though to make it mandatory.

It should always provide it though; Versioned relies on it for example.

hm

$sql = new SQLSelect('"ID"', '"'.$tableName.'"', '"'.$step['foreignkey'].'" IN ('.implode(',', $ids).')');
singleton($step['class'])->extend('augmentSQL', $sql);
$ids = $sql->execute()->column();

Should probably be:

$ids = DataObject::get($step['class'])
  ->filter($step['foreignkey'], $ids)
  ->column('ID');

Not sure why it's written in such a convoluted way.

Similarly for the other relations... stop trying to do raw-sql, and just use the ORM the way it's meant to be called?

from silverstripe-fulltextsearch.

tractorcow avatar tractorcow commented on August 15, 2024

Had a guess at how the code would look all up:

foreach ($derivation['chain'] as $step) {
    if ($step['through'] == 'has_one') {
        $ids = DataObject::get($step['class'])
            ->filter($step['foreignkey'], $ids)
            ->column('ID');
    } elseif ($step['through'] == 'has_many') {
        // Get many ids by querying component with alternate set of foreign ids
        $ids = DataObject::singleton($step['otherclass'])
            ->getComponents($step['method'], $ids)
            ->column('ID');
    }

    if (empty($ids)) {
        break;
    }
}

This makes use of the fact that you can mock a HasManyList with a set of foreign $id keys (instead of a single parent id).

Good thing I added that second arg to getComponents() :)

from silverstripe-fulltextsearch.

michalkleiner avatar michalkleiner commented on August 15, 2024

Affecting MBIE on a CWP project using 2.1 recipe

from silverstripe-fulltextsearch.

UndefinedOffset avatar UndefinedOffset commented on August 15, 2024

This also seems to affect Versioned objects as well in at least SilverStripe 4.3.0, Versioned requires a DataQuery as the second argument even though it's defined as accepting null as a parameter (see here).

from silverstripe-fulltextsearch.

michalkleiner avatar michalkleiner commented on August 15, 2024

The proposed PR works for us on the project, just need to sort the tests. Will try looking at it ASAP.

from silverstripe-fulltextsearch.

michalkleiner avatar michalkleiner commented on August 15, 2024

Back on this again, only 4 years after the initial report.

from silverstripe-fulltextsearch.

tractorcow avatar tractorcow commented on August 15, 2024

@michalkleiner I haven't used SOLR for a few years, but revisiting, I think the code example I pasted above should still fix the issue. I suggest throwing it into a PR and testing it out on a few live SOLR indexes to see if it works.

from silverstripe-fulltextsearch.

michalkleiner avatar michalkleiner commented on August 15, 2024

@tractorcow it works for us on a project, yes.
So you reckon it's rather about the failing test that might need adjusting?

from silverstripe-fulltextsearch.

michalkleiner avatar michalkleiner commented on August 15, 2024

Phew, ok, two new PRs with the tests passing and using the simplified DataObject::get approach.

from silverstripe-fulltextsearch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.