Now this is the sort of problem I would help others with but I am flummoxed. 
I am creating new categories in an import routine, e.g.

$this-&gt;magObject = Mage::getModel("catalog/category");
$this-&gt;magObject-&gt;setName($item["name"]);
$this-&gt;magObject-&gt;setData("agilityId",$item["id"]);
$this-&gt;magObject-&gt;setIsActive($this-&gt;isActive);
$this-&gt;magObject-&gt;setIsAnchor($this-&gt;isAnchor);
$this-&gt;magObject-&gt;setPageLayout($this-&gt;pageLayout);
$this-&gt;magObject-&gt;setStoreId(Mage::app()-&gt;setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID)); 
//$this-&gt;magObject-&gt;setPath ("1/2/6") ); //actually got by getting path of specific required parent
$this-&gt;magObject-&gt;save();


Without the setPath it saves fine, but with the wrong path (obviously).  When the setPath is included, nothing happens.  I know that there are devious magento elements at work that prevent writing to _entity tables unless certain circumstances are met but I thought I was meeting them .   I am already performing the usual

define("ADMIN_STORE_ID",1);
//...
Mage::app();
Mage::setIsDeveloperMode(true);
Mage::app()-&gt;setCurrentStore(Mage::getModel('core/store')-&gt;load(Mage_Core_Model_App::ADMIN_STORE_ID));


at the start but in this instance it just is not working.  I have similar scripts on other sites that do work.  Only difference with this site is that there are multiple store fronts

3 UK
7 Spanish
5 German
6 French
1 Default Store View


Anyone spot something obvious that I am missing, whilst I still have some hair left?

Oh this is using Magento 1.9.1.1.


Question: Evaluating an integrals by appropriate substitution
Answer: Let $u^2=1+x$. Then $2u\,du =dx$. Using the fact that $x=u^2-1$, we find that $x^2+1=u^4-2u^2+2$. 

Substituting, we find that our integral is
$$\int \frac{(u^4-2u^2+2)(2u)}{u}\,du.$$
There is cancellation, and we have reached
$$\int (2u^4-4u^2+4)\,du$$
which is
$$\frac{2}{5}u^5 -\frac{4}{3}u^3+4u+C.$$
Now replace $u$ by $(x+1)^{1/2}$.