/**
  * @param $computers_id
  * @param $date
  * @param $computer_updates
  * @return array
  */
 static function addInfocomsForComputer($computers_id, $date, $computer_updates)
 {
     global $DB;
     $infocom = new Infocom();
     $use_date = substr($date, 0, 10);
     if ($infocom->getFromDBByQuery("WHERE `items_id` = {$computers_id} AND `itemtype` = 'Computer'")) {
         if (empty($infocom->fields['use_date']) || $infocom->fields['use_date'] == 'NULL') {
             //add use_date
             $infocom->update(array('id' => $infocom->fields['id'], 'use_date' => $use_date));
         }
     } else {
         //add infocom
         $infocom->add(array('items_id' => $computers_id, 'itemtype' => 'Computer', 'use_date' => $use_date));
     }
     //Add lock
     $ocslink = new PluginOcsinventoryngOcslink();
     if ($ocslink->getFromDBforComputer($computers_id)) {
         $cfg_ocs = PluginOcsinventoryngOcsServer::getConfig($ocslink->fields["plugin_ocsinventoryng_ocsservers_id"]);
         if ($cfg_ocs["use_locks"]) {
             $computer_updates[] = "use_date";
             $query = "UPDATE `glpi_plugin_ocsinventoryng_ocslinks`\n                         SET `computer_update` = '" . addslashes(exportArrayToDB($computer_updates)) . "'\n                         WHERE `computers_id` = '{$computers_id}'";
             $DB->query($query);
         }
     }
     return $computer_updates;
 }
예제 #2
0
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

Ocsinventoryng plugin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with ocsinventoryng. If not, see <http://www.gnu.org/licenses/>.
---------------------------------------------------------------------------------------------------------------------------------------------------- */
// Ensure current directory when run from crontab
chdir(dirname($_SERVER["SCRIPT_FILENAME"]));
include '../../../inc/includes.php';
ini_set('display_errors', 1);
restore_error_handler();
if (!isset($_SERVER['argv'][1])) {
    die("usage testsync.php <computerid>\n");
}
$link = new PluginOcsinventoryngOcslink();
if (!$link->getFromDBforComputer($_SERVER['argv'][1])) {
    die("unknow computer\n");
}
printf("Device: %s\n", $link->getField('ocs_deviceid'));
$timer = new Timer();
$timer->start();
$prof = new XHProf("OCS sync");
PluginOcsinventoryngOcsServer::updateComputer($link->getID(), $link->getField('plugin_ocsinventoryng_ocsservers_id'), 1, 1);
unset($prof);
printf("Done in %s\n", $timer->getTime());
예제 #3
0
/**
 * Checking locks before updating
 * @param type $item
 */
function plugin_ocsinventoryng_pre_item_update($item)
{
    if ($item->fields['itemtype'] == "Computer") {
        $ocslink = new PluginOcsinventoryngOcslink();
        if ($ocslink->getFromDBforComputer($item->fields['items_id'])) {
            $cfg_ocs = PluginOcsinventoryngOcsServer::getConfig($ocslink->fields["plugin_ocsinventoryng_ocsservers_id"]);
            if ($cfg_ocs["use_locks"]) {
                $field_set = false;
                $computers_update = importArrayFromDB($ocslink->fields['computer_update']);
                if (in_array('use_date', $computers_update)) {
                    if (isset($item->input["use_date"]) && $item->input["use_date"] != $item->fields["use_date"]) {
                        $field_set = true;
                        $item->input["use_date"] = $item->fields["use_date"];
                    }
                }
                if ($field_set) {
                    Session::addMessageAfterRedirect(__("The startup date field is locked by ocsinventoryng please unlock it before update.", "ocsinventoryng"), true, ERROR);
                }
            }
        }
    }
}