It’s a fair amount of work, but I’ve managed to get rid of the deprecation notices in all of my extras.
Basically, you do something like this:
$isMODX3 = $modx->getVersionData()['version'] >= 3;
$prefix = $isMODX3
? 'MODX\Revolution\\'
: '';
$doc = $modx->getObject($prefix . 'modResource',
array('pagetitle' => 'myPage'));
Once you have the $prefix
, you have to correct all calls to getObject(), getCollection(), getIterator(), newObject(), getCount(), newQuery, and new. There are separate prefixes for transport packages, media sources, and mail.
You also need to get rid of any calls to instanceof
.
That’s not as difficult as it sounds if you have a good code editor that lets you search multiple files.
It gets significantly more complicated, though, if you have processors or classes that are subclasses of MODX objects.
In those cases, you need to create a phantom parent class something like this:
$v = include MODX_CORE_PATH . 'docs/version.inc.php';
$isMODX3 = $v['version'] >= 3;
$prefix = $isMODX3? 'MODX\Revolution\\' : '';
if ($isMODX3) {
abstract class ExampleDynamicParentchunkgetlist extends MODX\Revolution\Processors\Element\Chunk\GetList {
}
} else {
$includeFile = MODX_CORE_PATH . 'model/modx/processors/element/chunk/getlist.class.php';
if (!class_exists($prefix . 'modChunkGetListProcessor')) {
require $includeFile;
}
abstract class ExampleDynamicParentchunkgetlist extends modChunkGetlistProcessor {
}
}
class ExampleChunkGetlistProcessor extends ExampleDynamicParentchunkgetlist {
public $classKey = 'modChunk';
/* Your class code here */
}
Your call whether it’s worth the effort.