01.28 php saved
hiromi
Tags add more
 
Note
hiromi did not leave a note
  1. 1443,1496d1442
  2. +
  3. +         $oldLinks = array();
  4. +         $toDeleteLinks = array();
  5. +
  6. +         if ($this->hasAndBelongsToMany[$assoc]['unique']) {
  7. +           $conditions = array_merge(
  8. +             array($join . '.' . $this->hasAndBelongsToMany[$assoc]['foreignKey'] => $id),
  9. +             (array)$this->hasAndBelongsToMany[$assoc]['conditions']
  10. +           );
  11. +           $links = $this->{$join}->find('all', array(
  12. +             'conditions' => $conditions,
  13. +             'recursive' => empty($this->hasAndBelongsToMany[$assoc]['conditions']) ? -1 : 0,
  14. +             'fields' => $this->hasAndBelongsToMany[$assoc]['associationForeignKey']
  15. +           ));
  16. +
  17. +           $associationForeignKey = "{$join}." . $this->hasAndBelongsToMany[$assoc]['associationForeignKey'];
  18. +           $oldLinks = Set::extract($links, "{n}.{$associationForeignKey}");
  19. +          
  20. +           $toDeleteLinks = array();
  21. +          
  22. +           $newLinks = array();
  23. +           foreach((array)$data as $row){
  24. +             $newLink = null;
  25. +            
  26. +             if ((is_string($row) && (strlen($row) == 36 || strlen($row) == 16)) || is_numeric($row)) {
  27. +               $newLink = $row;
  28. +             } elseif (isset($row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
  29. +               if(isset($row[$this->{$join}->primaryKey])){
  30. +                 continue;
  31. +               }
  32. +               $newLink = $row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']];
  33. +             } elseif (isset($row[$join]) && isset($row[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']])) {
  34. +               if(isset($row[$join][$this->{$join}->primaryKey])){
  35. +                 continue;
  36. +               }
  37. +               $newLink = $row[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']];
  38. +             }
  39. +            
  40. +             if(!$newLink){
  41. +               continue;
  42. +             }
  43. +            
  44. +             $newLinks[] = $newLink;
  45. +           }
  46. +           $newLinks = array_unique($newLinks);
  47. +          
  48. +           $toDeleteLinks = array_diff($oldLinks,$newLinks);
  49. +          
  50. +           if (!empty($toDeleteLinks)) {
  51. +        $conditions[$associationForeignKey] = $toDeleteLinks;
  52. +             $db->delete($this->{$join}, $conditions);
  53. +           }
  54. +         }
  55. +
  56. 1499,1501d1444
  57. +             if(in_array($row,$oldLinks)){
  58. +               continue;
  59. +             }
  60. 1513,1516d1455
  61. +             if(in_array($row[$this->hasAndBelongsToMany[$assoc]['associationForeignKey']],$oldLinks)
  62. +               && !isset($row[$this->{$join}->primaryKey]) ){
  63. +               continue;
  64. +             }
  65. 1519,1522d1457
  66. +             if(in_array($row[$join][$this->hasAndBelongsToMany[$assoc]['associationForeignKey']],$oldLinks)
  67. +                && !isset($row[$join][$this->{$join}->primaryKey]) ){
  68. +               continue;
  69. +             }
  70. 1526c1461,1479
  71. +        
  72. ---
  73. -
  74. -         if ($this->hasAndBelongsToMany[$assoc]['unique']) {
  75. -           $conditions = array_merge(
  76. -             array($join . '.' . $this->hasAndBelongsToMany[$assoc]['foreignKey'] => $id),
  77. -             (array)$this->hasAndBelongsToMany[$assoc]['conditions']
  78. -           );
  79. -           $links = $this->{$join}->find('all', array(
  80. -             'conditions' => $conditions,
  81. -             'recursive' => empty($this->hasAndBelongsToMany[$assoc]['conditions']) ? -1 : 0,
  82. -             'fields' => $this->hasAndBelongsToMany[$assoc]['associationForeignKey']
  83. -           ));
  84. -
  85. -           $associationForeignKey = "{$join}." . $this->hasAndBelongsToMany[$assoc]['associationForeignKey'];
  86. -           $oldLinks = Set::extract($links, "{n}.{$associationForeignKey}");
  87. -           if (!empty($oldLinks)) {
  88. -        $conditions[$associationForeignKey] = $oldLinks;
  89. -             $db->delete($this->{$join}, $conditions);
  90. -           }
  91. -         }
  92. 1540d1492
  93. +        
  94.  
Parsed in 0.218 seconds, using GeSHi 1.0.7.14

Modify this Paste