Imported Resources not available in frontend

Hi, I’m having troubles accessing imported resources. We pull in articles via an API and import them into Modx by using $doc = $modx->newObject('modDocument');

We set all properties like this
$doc->set(‘parent’,$this->parent);
$doc->set(‘pagetitle’,$item->title);
$doc->set(‘longtitle’,$item->title);
$doc->set(‘alias’,$item->seoName);
$doc->set(‘template’,$this->template);
$doc->set(‘pub_date’,$item->publishedFrom);
$doc->setContent($item->body);

and create the alias and URI:
$parentResourceTitle = $modx->getObject(‘modResource’,$this->parent)->get(‘pagetitle’);
$parentAlias = $doc->cleanAlias($parentResourceTitle);

$alias = $doc->get('alias'); // get the generated alias
$doc->set('uri', $parentAlias.'/'.$alias.'.html');
$doc->save();

Evertying works, the resources are available in the backend. All fields filled correct, but the articles are not available using their URL. Until… we clear the cache manually or we hit Refresh URIs via the backend. Since articles are added every x-minutes. We need the articles/urls to be available without manually clearling cache/refresh URIs.

Tried Opengeeks script (https://gist.github.com/opengeek/917662); but since we have to much articles, this doesn’t seem to work

Anybody got suggestions?

Maybe you could just clear the cache programmatically after the import.

$modx->cacheManager->refresh();

Already tried this; killed my site completely. Invalidated the complete cache making front- and backend unavailable until clearing the cache folder manually.

And… since we import articles every 5 minutes, we would be clearing the cache each 5 minutes. This would/could mean a big performance lag.

Try adding this to your code after saving all resources:

$modx->reloadContext('web');

Change ‘web’ to the context the resources are in if it’s not the web context.

Bob, thanks for your reply. No luck so far. Since I’m able to create the alias and URI, we just reference these instead of [[~[[+id]]]] - which seems to cause the issue.

I’m not sure I understand how the tag is causing problems. Were you using [[~[[+id]]]] in your PHP code?

Maybe you’re doing this already, but if you’re creating the alias, this is often a good idea:

$alias = 'something';
$alias= $resource->cleanAlias($alias);

If you’ve set the pagetitle first and want the alias to match it, you can do this:

$alias= $resource->cleanAlias($pagetitle);

Try this: disable this setting: cache_alias_map
this worked for me

If you create a new modResource object and set alias, then the alias is already cleaned.

Absolutely correct, dimmy, as long as you call set() for the alias. I forgot about this:

public function set($k, $v= null, $vType= '') {
        $rt= false;
        switch ($k) {
            case 'alias' :
                $v= $this->cleanAlias($v);