Esempio n. 1
0
</td>
  <td><?php 
    echo user_link($object['User']);
    ?>
</td>
  <td><?php 
    echo ModificationTable::getType($object);
    ?>
</td>
  <td>
    <strong>
    <?php 
    if ($rel) {
        ?>
      <?php 
        echo link_to(RelationshipTable::getName($rel), RelationshipTable::generateRoute($rel));
        ?>
    <?php 
    } else {
        ?>
      <?php 
        echo link_to($object['object_name'], 'relationship/modifications?id=' . $object['object_id']);
        ?>
    <?php 
    }
    ?>
    </strong>
  </td>
</tr>

<?php 
 protected function execute($arguments = array(), $options = array())
 {
     $this->init($arguments, $options);
     if ($this->testMode) {
         echo "TESTING -- no changes will be saved\n";
     }
     $merge_modification = $this->getLastMerge();
     if (!$merge_modification) {
         die;
     }
     $this->entity2_id = $merge_modification['object_id'];
     $this->entity1 = Doctrine::getTable('Entity')->find($this->entity1_id);
     $this->entity2 = Doctrine::getTable('Entity')->find($this->entity2_id);
     //GET ALL EXTENSIONS ADDED WITHIN A CERTAIN RANGE OF MODIFICATION TIME
     $sql = "SELECT m.* FROM extension_record er LEFT JOIN modification m on m.object_id = er.id AND m.object_model = ? WHERE er.entity_id = ? AND TIME_TO_SEC(TIMEDIFF(?,m.created_at)) < 100 and is_create = 1";
     $stmt = $this->db->execute($sql, array('ExtensionRecord', $this->entity1_id, $merge_modification['created_at']));
     $ext_mods = $stmt->fetchAll(PDO::FETCH_ASSOC);
     //REMOVE EXTENSIONS THAT WERE ADDED
     if (count($ext_mods)) {
         foreach ($ext_mods as $m) {
             $er = Doctrine::getTable("ExtensionRecord")->find($m['object_id']);
             $ed = Doctrine::getTable("ExtensionDefinition")->find($er['definition_id']);
             if ($ed) {
                 $this->printDebug("removing " . $ed['name'] . " extension now");
                 if (!$this->testMode) {
                     $this->entity1->removeExtension($ed['name']);
                     $this->entity1->save();
                 }
             }
         }
     }
     //GET MODIFIED FIELDS
     $sql = "SELECT mf.* FROM modification_field mf LEFT JOIN modification m ON m.id = mf.modification_id WHERE m.object_model = ? AND m.object_id = ? AND TIME_TO_SEC(TIMEDIFF(?,m.created_at)) < 100";
     $stmt = $this->db->execute($sql, array('Entity', $this->entity1_id, $merge_modification['created_at']));
     $ent_mods = $stmt->fetchAll(PDO::FETCH_ASSOC);
     foreach ($ent_mods as $ent_mod) {
         $this->printDebug("\tchange " . $ent_mod['field_name'] . ": " . $ent_mod['new_value'] . " back to " . $ent_mod['old_value'] . "");
     }
     //UNDELETE ENTITY 2
     $sql = "UPDATE entity e SET e.is_deleted = 0 WHERE e.id = ?";
     if (!$this->testMode) {
         $stmt = $this->db->execute($sql, array($this->entity2_id));
     }
     //GET ALL MODIFICATIONS THAT WE KNOW SOMETHING ABOUT
     $sql = "SELECT * FROM modification_field WHERE field_name like ? AND old_value = ? AND new_value = ?";
     $stmt = $this->db->execute($sql, array('%_id%', $this->entity2_id, $this->entity1_id));
     $all_mod_fields = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $rels_updated = array();
     foreach ($all_mod_fields as $mod_field) {
         $mod_id = $mod_field['modification_id'];
         $mod = Doctrine::getTable('Modification')->find($mod_id);
         if ($mod->object_model == 'Relationship') {
             //set merge to true or false?
             $rel = Doctrine::getTable("Relationship")->find($mod['object_id']);
             if ($rel) {
                 if (strtotime($rel->updated_at) - strtotime($merge_modification['created_at']) > 100) {
                     $rels_updated[] = $rel;
                 } else {
                     $prevName = RelationshipTable::getName($rel);
                     $rel[$mod_field['field_name']] = $this->entity2_id;
                     if (!$this->testMode) {
                         $rel->save();
                     }
                     $this->printDebug($prevName . " changed to " . RelationshipTable::getName($rel));
                     //UPDATE THE LINKS
                     $links = Doctrine::getTable("Link")->findByRelationshipId($rel->id);
                     foreach ($links as $l) {
                         if ($l->entity1_id == $this->entity1_id) {
                             $l->entity1_id = $this->entity2_id;
                         } else {
                             if ($l->entity2_id == $this->entity1_id) {
                                 $l->entity2_id = $this->entity2_id;
                             }
                         }
                         if (!$this->testMode) {
                             $l->save();
                         }
                         $this->printDebug("link updated");
                     }
                 }
             } else {
                 $this->printDebug("\tNo relationship found");
             }
         } else {
             $this->revertObject($mod->object_model, $mod['object_id'], $mod_field['field_name']);
         }
     }
     //GET ALL REFERENCES ON ENTITY 1 THAT SHOULD ACTUALLY BE FOR ENTITY 2
     $sql = "SELECT * FROM reference WHERE object_id = ? AND object_model = ? AND TIME_TO_SEC(TIMEDIFF(?,updated_at)) < 100";
     $stmt = $this->db->execute($sql, array($this->entity1_id, 'Entity', $merge_modification['created_at']));
     $references = $stmt->fetchAll(PDO::FETCH_ASSOC);
     foreach ($references as $ref) {
         if (!$this->testMode) {
             $ref['object_id'] = $this->entity2_id;
         }
         $this->printDebug("Reference " . $ref['id'] . " changed");
     }
     foreach ($rels_updated as $rel) {
         $this->printDebug("updated after: " . RelationshipTable::getName($rel));
     }
 }
Esempio n. 3
0
<?php

slot('header_text', RelationshipTable::getName($relationship));
slot('header_link', RelationshipTable::getInternalUrl($relationship));
slot('description_meta', RelationshipTable::generateMetaDescription($relationship));
?>

<?php 
if (!$relationship['is_deleted'] && isset($show_actions) && $show_actions) {
    ?>
  <?php 
    slot('header_actions', array('edit' => array('url' => 'relationship/edit?id=' . $relationship['id'], 'credential' => 'editor'), 'flag' => array('url' => 'home/contact?type=flag'), 'remove' => array('url' => 'relationship/remove?id=' . $relationship['id'], 'options' => 'post=true confirm=Are you sure you want to remove this relationship?', 'credential' => 'deleter'), 'refresh' => array('url' => RelationshipTable::getInternalUrl($relationship, 'refresh', array('ref' => $sf_request->getUri())), 'credential' => 'admin')));
    ?>
  
<?php 
}