Esempio n. 1
0
 public function testHandler_process_subscription()
 {
     midcom::get('auth')->request_sudo('org.openpsa.sales');
     $product = org_openpsa_products_product_dba::get_cached(self::$_product->id);
     $product->delivery = org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION;
     $product->update();
     $deliverable_attributes = array('salesproject' => self::$_salesproject->id, 'product' => self::$_product->id, 'start' => time(), 'continuous' => true, 'unit' => 'q', 'orgOpenpsaObtype' => org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION);
     $deliverable = $this->create_object('org_openpsa_sales_salesproject_deliverable_dba', $deliverable_attributes);
     $deliverable->update();
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_POST = array('order' => true);
     $url = $this->run_relocate_handler('org.openpsa.sales', array('deliverable', 'process', $deliverable->guid));
     $this->assertEquals($url, 'salesproject/' . self::$_salesproject->guid . '/');
     $deliverable->refresh();
     $this->assertEquals(org_openpsa_sales_salesproject_deliverable_dba::STATUS_ORDERED, $deliverable->state);
     $mc = new org_openpsa_relatedto_collector($deliverable->guid, 'midcom_services_at_entry_dba');
     $mc->add_object_order('start', 'DESC');
     $at_entries = $mc->get_related_objects();
     $this->assertEquals(1, sizeof($at_entries));
     $this->register_object($at_entries[0]);
     $_POST = array('run_cycle' => true, 'at_entry' => $at_entries[0]->guid);
     $url = $this->run_relocate_handler('org.openpsa.sales', array('deliverable', 'process', $deliverable->guid));
     $this->assertEquals($url, 'salesproject/' . self::$_salesproject->guid . '/');
     $deliverable->refresh();
     $mc = new org_openpsa_relatedto_collector($deliverable->guid, 'midcom_services_at_entry_dba');
     $mc->add_object_order('start', 'DESC');
     $at_entries = $mc->get_related_objects();
     $this->assertEquals(1, sizeof($at_entries));
     $this->register_object($at_entries[0]);
     midcom::get('auth')->drop_sudo();
 }
Esempio n. 2
0
 /**
  * Helper function to alter the schema based on the current operation
  */
 private function _modify_schema()
 {
     $mc = new org_openpsa_relatedto_collector($this->_deliverable->guid, 'midcom_services_at_entry_dba');
     $mc->add_object_order('start', 'ASC');
     $mc->set_object_limit(1);
     $at_entries = $mc->get_related_objects();
     if (sizeof($at_entries) != 1) {
         return;
     }
     $entry = $at_entries[0];
     $fields =& $this->_schemadb['subscription']->fields;
     $fields['next_cycle']['hidden'] = false;
     $fields['next_cycle']['default'] = array('next_cycle_date' => date('Y-m-d', $entry->start));
     $fields['at_entry']['default'] = $entry->id;
 }
Esempio n. 3
0
midcom::get('auth')->require_admin_user();
// Ensure this is not buffered
midcom::get('cache')->content->enable_live_mode();
while (@ob_end_flush()) {
    midcom::get()->disable_limits();
}
echo "<h1>Cleanup deliverable AT entries:</h1>\n";
$qb = org_openpsa_sales_salesproject_deliverable_dba::new_query_builder();
$qb->add_constraint('orgOpenpsaObtype', '=', org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION);
$qb->add_constraint('state', '>=', org_openpsa_sales_salesproject_deliverable_dba::STATUS_ORDERED);
$deliverables = $qb->execute();
echo "<pre>\n";
flush();
foreach ($deliverables as $deliverable) {
    $mc = new org_openpsa_relatedto_collector($deliverable->guid, 'midcom_services_at_entry_dba');
    $mc->add_object_order('start', 'DESC');
    $at_entries = $mc->get_related_objects();
    if (sizeof($at_entries) <= 1) {
        continue;
    }
    echo "Removing duplicate AT entries for deliverable #{$deliverable->id} " . $deliverable->title . "\n";
    flush();
    $first = true;
    foreach ($at_entries as $entry) {
        if ($first) {
            $first = false;
            echo "Keeping entry for " . strftime('%x %X', $entry->start) . "\n";
            flush();
            continue;
        }
        echo "Deleting entry for " . strftime('%x %X', $entry->start) . "\n";