Example #1
0
 /**
  * Check delete / purge on a template of printer
  */
 public function testPrinterTemplate()
 {
     $printer = new Printer();
     // Create
     $id[0] = $printer->add(array('name' => "Printer 1", 'entities_id' => 0, 'is_template' => 1));
     $this->assertGreaterThan(0, $id[0], "Fail to create Printer Template");
     $this->assertTrue($printer->getFromDB($id[0]), "Fail: can't read Template");
     $this->assertEquals(0, $printer->fields['is_deleted'], "Fail: is_deleted set");
     $this->assertEquals(1, $printer->fields['is_template'], "Fail: is_template not set");
     // Delete (= purge)
     $this->assertTrue($printer->delete(array('id' => $id[0]), 0), "Fail: can't delete Template");
     $this->assertFalse($printer->getFromDB($id[0]), "Fail: can read Template (deleted)");
 }
Example #2
0
 /**
  * @covers Printer::delete
  * @covers Printer::restore
  */
 public function testDelete()
 {
     $obj = new Printer();
     $this->assertTrue($obj->maybeDeleted());
     // Add
     $id = $obj->add(['name' => __METHOD__, 'entities_id' => getItemByTypeName('Entity', '_test_root_entity', true)]);
     $this->assertGreaterThan(0, $id);
     $this->assertTrue($obj->getFromDB($id));
     $this->assertEquals(0, $obj->getField('is_deleted'));
     $this->assertEquals(0, $obj->isDeleted());
     // Delete
     $this->assertTrue($obj->delete(['id' => $id], 0));
     $this->assertTrue($obj->getFromDB($id));
     $this->assertEquals(1, $obj->getField('is_deleted'));
     $this->assertEquals(1, $obj->isDeleted());
     // Restore
     $this->assertTrue($obj->restore(['id' => $id], 0));
     $this->assertTrue($obj->getFromDB($id));
     $this->assertEquals(0, $obj->getField('is_deleted'));
     $this->assertEquals(0, $obj->isDeleted());
     // Purge
     $this->assertTrue($obj->delete(['id' => $id], 1));
     $this->assertFalse($obj->getFromDB($id));
 }
Example #3
0
 /**
  * @covers Printer::delete
  * @covers Printer::restore
  */
 public function testDelete()
 {
     $obj = new Printer();
     $this->assertTrue($obj->maybeDeleted());
     // Add
     $id = $obj->add(['name' => __METHOD__]);
     $this->assertGreaterThan(0, $id);
     $this->assertTrue($obj->getFromDB($id));
     $this->assertEquals(0, $obj->getField('is_deleted'));
     $this->assertEquals(0, $obj->isDeleted());
     // Delete
     $this->assertTrue($obj->delete(['id' => $id], 0));
     $this->assertTrue($obj->getFromDB($id));
     $this->assertEquals(1, $obj->getField('is_deleted'));
     $this->assertEquals(1, $obj->isDeleted());
     // Restore
     $this->assertTrue($obj->restore(['id' => $id], 0));
     $this->assertTrue($obj->getFromDB($id));
     $this->assertEquals(0, $obj->getField('is_deleted'));
     $this->assertEquals(0, $obj->isDeleted());
     // Purge
     $this->assertTrue($obj->delete(['id' => $id], 1));
     $this->assertFalse($obj->getFromDB($id));
 }
 /**
  * @param $IDS array
  */
 function putOldPrintersInTrash($IDS = array())
 {
     $printer = new Printer();
     foreach ($IDS as $id) {
         $printer->delete(array('id' => $id));
     }
 }
Example #5
0
    $_GET["order"] = "";
}
if (!isset($_GET["withtemplate"])) {
    $_GET["withtemplate"] = "";
}
$print = new Printer();
if (isset($_POST["add"])) {
    $print->check(-1, 'w', $_POST);
    if ($newID = $print->add($_POST)) {
        Event::log($newID, "printers", 4, "inventory", $_SESSION["glpiname"] . "  " . $LANG['log'][20] . "  " . $_POST["name"] . ".");
    }
    glpi_header($_SERVER['HTTP_REFERER']);
} else {
    if (isset($_POST["delete"])) {
        $print->check($_POST["id"], 'd');
        $print->delete($_POST);
        Event::log($_POST["id"], "printers", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][22]);
        $print->redirectToList();
    } else {
        if (isset($_POST["restore"])) {
            $print->check($_POST["id"], 'd');
            $print->restore($_POST);
            Event::log($_POST["id"], "printers", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][23]);
            $print->redirectToList();
        } else {
            if (isset($_REQUEST["purge"])) {
                $print->check($_REQUEST["id"], 'd');
                $print->delete($_REQUEST, 1);
                Event::log($_REQUEST["id"], "printers", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][24]);
                $print->redirectToList();
            } else {
 public function testPrinterDicoIgnoreImport()
 {
     global $DB;
     $DB->connect();
     self::restore_database();
     $_SESSION['glpiactive_entity'] = 0;
     $_SESSION["plugin_fusioninventory_entity"] = 0;
     $_SESSION["glpiname"] = 'Plugin_FusionInventory';
     $pfConfig = new PluginFusioninventoryConfig();
     $computer = new Computer();
     /*
      * TODO: maybe we could use some dataProvider here ?
      */
     // Add dictionnary rule for ignore import for printer p2
     $rulecollection = new RuleDictionnaryPrinterCollection();
     $rule = $rulecollection->getRuleClass();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'Ignore import';
     $input['match'] = 'AND';
     $input['sub_type'] = 'RuleDictionnaryPrinter';
     $input['ranking'] = 1;
     $rule_id = $rule->add($input);
     // Add criteria
     $rule = $rulecollection->getRuleClass();
     $rulecriteria = new RuleCriteria(get_class($rule));
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "name";
     $input['pattern'] = 'p2';
     $input['condition'] = 0;
     $rulecriteria->add($input);
     // Add action
     $ruleaction = new RuleAction(get_class($rule));
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['action_type'] = 'assign';
     $input['field'] = '_ignore_import';
     $input['value'] = '1';
     $ruleaction->add($input);
     // Add dictionnary rule for ignore import for printer p3
     $rulecollection = new RuleDictionnaryPrinterCollection();
     $rule = $rulecollection->getRuleClass();
     $input = array();
     $input['is_active'] = 1;
     $input['name'] = 'rename';
     $input['match'] = 'AND';
     $input['sub_type'] = 'RuleDictionnaryPrinter';
     $input['ranking'] = 2;
     $rule_id = $rule->add($input);
     // Add criteria
     $rule = $rulecollection->getRuleClass();
     $rulecriteria = new RuleCriteria(get_class($rule));
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['criteria'] = "name";
     $input['pattern'] = 'p3';
     $input['condition'] = 0;
     $rulecriteria->add($input);
     // Add action
     $ruleaction = new RuleAction(get_class($rule));
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['action_type'] = 'assign';
     $input['field'] = 'name';
     $input['value'] = 'p3bis';
     $ruleaction->add($input);
     // Add action
     $ruleaction = new RuleAction(get_class($rule));
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['action_type'] = 'assign';
     $input['field'] = 'manufacturer';
     $input['value'] = '1';
     $ruleaction->add($input);
     // Add action
     $ruleaction = new RuleAction(get_class($rule));
     $input = array();
     $input['rules_id'] = $rule_id;
     $input['action_type'] = 'assign';
     $input['field'] = 'is_global';
     $input['value'] = '0';
     $ruleaction->add($input);
     $pfici = new PluginFusioninventoryInventoryComputerInventory();
     $_SESSION['plugin_fusioninventory_agents_id'] = 1;
     $pfici->sendCriteria("toto", $this->a_computer1_beforeformat);
     $computer->getFromDB(1);
     $this->assertEquals('ggheb7ne7', $computer->fields['serial'], 'Computer not updated correctly');
     $a_printers = getAllDatasFromTable("glpi_printers");
     $this->assertEquals(0, countElementsInTable('glpi_printers'), 'Printer p2 may be ignored (' . print_r($a_printers, TRUE) . ')');
     $printer = new Printer();
     $printer->delete(array('id' => 1), 1);
     $DB->query("TRUNCATE TABLE `glpi_printers`");
 }
Example #7
0
 /**
  * Delete all old printers of a computer.
  *
  * @param $glpi_computers_id integer : glpi computer id.
  *
  * @return nothing.
  **/
 static function resetPrinters($glpi_computers_id)
 {
     global $DB;
     $query = "SELECT*\n                FROM `glpi_computers_items`\n                WHERE `computers_id` = '{$glpi_computers_id}'\n                      AND `itemtype` = 'Printer'";
     $result = $DB->query($query);
     if ($DB->numrows($result) > 0) {
         $conn = new Computer_Item();
         while ($data = $DB->fetch_assoc($result)) {
             $conn->delete(array('id' => $data['id']));
             $query2 = "SELECT COUNT(*)\n                       FROM `glpi_computers_items`\n                       WHERE `items_id` = '" . $data['items_id'] . "'\n                             AND `itemtype` = 'Printer'";
             $result2 = $DB->query($query2);
             $printer = new Printer();
             if ($DB->result($result2, 0, 0) == 1) {
                 $printer->delete(array('id' => $data['items_id']), 1);
             }
         }
     }
 }
Example #8
0
    $_GET["withtemplate"] = "";
}
$print = new Printer();
if (isset($_POST["add"])) {
    $print->check(-1, CREATE, $_POST);
    if ($newID = $print->add($_POST)) {
        Event::log($newID, "printers", 4, "inventory", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"]));
        if ($_SESSION['glpibackcreated']) {
            Html::redirect($print->getFormURL() . "?id=" . $newID);
        }
    }
    Html::back();
} else {
    if (isset($_POST["delete"])) {
        $print->check($_POST["id"], DELETE);
        $print->delete($_POST);
        Event::log($_POST["id"], "printers", 4, "inventory", sprintf(__('%s deletes an item'), $_SESSION["glpiname"]));
        $print->redirectToList();
    } else {
        if (isset($_POST["restore"])) {
            $print->check($_POST["id"], DELETE);
            $print->restore($_POST);
            Event::log($_POST["id"], "printers", 4, "inventory", sprintf(__('%s restores an item'), $_SESSION["glpiname"]));
            $print->redirectToList();
        } else {
            if (isset($_POST["purge"])) {
                $print->check($_POST["id"], PURGE);
                $print->delete($_POST, 1);
                Event::log($_POST["id"], "printers", 4, "inventory", sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
                $print->redirectToList();
            } else {
Example #9
0
        fMessaging::create('error', fURL::get(), $e->getMessage());
    }
    // Get manufacturers also for drop-down box
    #$manufacturers = fRecordSet::build('Manufacturer', NULL, array('name' => 'asc'));
    // Get list of models
    $models = Model::getSimple($db);
    include 'views/printers/addedit.php';
}
/**
 * Delete a printer
 */
if ($action == 'delete') {
    // Get ID
    $id = fRequest::get('id', 'integer');
    try {
        $p = new Printer($id);
        if (fRequest::isPost()) {
            $p->delete();
            fMessaging::create('success', fURL::get(), 'The printer ' . $p->getName() . ' was successfully deleted.');
            fURL::redirect(fURL::get());
        }
    } catch (fNotFoundException $e) {
        fMessaging::create('error', fURL::get(), 'The printer requested, ID ' . $id . ', could not be found.');
        fURL::redirect($manage_url);
    } catch (fExpectedException $e) {
        fMessaging::create('error', fURL::get(), $e->getMessage());
    } catch (fSQLException $e) {
        fMessaging::create('error', fURL::get(), 'Database error: ' . $e->getMessage());
    }
    include 'views/printers/delete.php';
}