This is kind of a two part question.
First you are saying:
This was in regards to our customer turning off some old categories, but the products still being searchable.
Instead of "disabling", I would create a script that changes the visibility from "Catalog, Search" to just "Catalog"
This code would look like something like this:
$productId = ???;
$product = Mage::getModel('catalog/product');
$product->load($productId);
$product->setVisibility(2);
$product->save();
You would also need code to search and switch the visibility back in the event it goes back into a Category.
Note: Since you have multiple websites, you may need to add code specifically to a website ID. Also, since you have multiple admins changing product data, a admin logger would be a great idea since I have heard horror stories about random admin users changing product data.
The second part of the question is
What do the above lines actually do?
The code does disabled and enable products, however it seems that you ran into a issue. There are other ways in doing this as well, however what you posted above is the most common way (especially on SE). Things I would look at is if your "status" attribute is a global or website variable. By default is "website". I would take a look at what when you are in the admin panel is if you are on the default view or if you are in the website specific view. The code above will always appear to be "Enabled" in the default view, but it will get disabled in the website view.
I would create a custom log in your script to see write what product was changed, and when it was changed.
I asked for a bounty, but these seems to be fixed after re run chmod 777 to pub.
Its very hard to develop in magento 2.
Edit:
Open up app/etc/di.xml
and find the virtualType name="developerMaterialization"
section. In that section you'll find an item name="view_preprocessed"
that needs to be modified or deleted. You can modify it by changing the contents from Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink to Magento\Framework\App\View\Asset\MaterializationStrategy\Copy
Delete the files under pub/static
to get rid of any existing symlinks. You may want to be careful not to delete the .htaccess
file.
Best Answer
You'll want to use
\Magento\Catalog\Api\ProductRepositoryInterface
Declare a dependency on it by adding it to your constructor
Then you can update the status and save it back with the following code in your method